In [1]:
# indexPdb.py
# ----------------------------------------------------------------------
# Copyright (2010) Aram Davtyan and Garegin Papoian
#
# Papoian's Group, University of Maryland at Collage Park
# http://papoian.chem.umd.edu/
#
# Last Update: 07/18/2011
# -------------------------------------------------------------------------

#import sys

#if len(sys.argv)!=5:
#	print
#	print " > " + sys.argv[0] + " fasta.file pdb_file index_file chain_id"
#	print
#	exit()

from Bio import pairwise2
from Bio.PDB.PDBParser import PDBParser
from Bio import SeqIO

def three2one(prot):
    """ translate a protein sequence from 3 to 1 letter code"""

    code = {"GLY" : "G", "ALA" : "A", "LEU" : "L", "ILE" : "I",
            "ARG" : "R", "LYS" : "K", "MET" : "M", "CYS" : "C",
            "TYR" : "Y", "THR" : "T", "PRO" : "P", "SER" : "S",
            "TRP" : "W", "ASP" : "D", "GLU" : "E", "ASN" : "N",
            "GLN" : "Q", "PHE" : "F", "HIS" : "H", "VAL" : "V",
            "M3L" : "K", "MSE" : "M", "CAS" : "C" }

    newprot = ""
    for a in prot:
        newprot += code.get(a, "X")

    return newprot

def getListOfValidAlignments(alignments, pdb_indexes):
    ialigns = []
    for i in range(0, len(alignments)):
        alignment = alignments[i]
        alseq_fasta = alignment[0]
        alseq_pdb = alignment[1]

        if len(alseq_fasta)!=len(alseq_pdb):
            print("Error using alignment too")
            print()
            exit()

        last_i_pdb = -1
        last_j = -1
        i_pdb = 0
        valid = True
        for j in range(0, len(alseq_pdb)):
                if alseq_pdb[j]!='-':
    #                                if last_i_pdb!=-1 and j - last_j > i_pdb - last_i_pdb:
                        if last_i_pdb!=-1 and j - last_j != pdb_indexes[i_pdb] - pdb_indexes[last_i_pdb]:
                                valid = False
                                break
                        last_i_pdb = i_pdb
                        last_j = j
                        i_pdb = i_pdb + 1
        if valid:
                ialigns.append(i)
    return ialigns

def getFastaSequance(fasta_file):
    inFASTA=open(fasta_file, 'r')
    inseq=SeqIO.read(inFASTA,'fasta')

    return str(inseq.seq)

def getPdbSequance(pdb_file, chain_id):
    pdb_indexes = []
    pdb_sequance = []

    p = PDBParser(PERMISSIVE=1)
    s = p.get_structure("",  pdb_file)
    pdb_id = pdb_file[0:-4]

    if not s[0].has_id(chain_id):
        print("PDB "+pdb_id+" doesn't have chain with id "+chain_id)
        print()
        exit()

    chain = s[0][chain_id]

    ires = 0
    for res in chain:
        is_regular_res = res.has_id('N') and res.has_id('CA') and res.has_id('C') and (res.get_resname()=='GLY' or res.has_id('CB'))
        res_id = res.get_id()[0]
        if (res_id ==' ' or res_id =='H_MSE' or res_id =='H_M3L' or res_id =='H_CAS') and is_regular_res:
                ires = ires + 1
                res_name = res.get_resname()
                residue_no = res.get_id()[1]
                pdb_sequance.append(res_name)
                pdb_indexes.append(residue_no)
        elif res_id !='W':
                print("Unknown residue in "+pdb_id+" with res_id "+res_id)

    pdb_seq = three2one(pdb_sequance)

    return pdb_seq, pdb_indexes

def getIndexArray(alignment, pdb_indexes):
    alseq_fasta = alignment[0]
    alseq_pdb = alignment[1]

    index_array = []
    i_fasta = 0
    i_pdb = 0
    for i in range(0, len(alseq_fasta)):
        if alseq_fasta[i]!='-':
            index_pdb = -1
            if alseq_pdb[i]!='-': index_pdb = pdb_indexes[i_pdb]
            index_array.append([i_fasta, index_pdb, alseq_fasta[i]])
            i_fasta = i_fasta + 1
        if alseq_pdb[i]!='-':
            i_pdb = i_pdb + 1

    return index_array

def writeIndexFile(fasta_file, pdb_file, index_file, chain_id):
#	from Bio import pairwise2
#	from Bio.PDB.PDBParser import PDBParser
#	from Bio import SeqIO

    pdb_id = pdb_file[0:-4]

#fasta_file = sys.argv[1]
#pdb_id = sys.argv[2]
#pdb_file = pdb_id+".pdb"
#index_file = sys.argv[3]
#chain_id = sys.argv[4]

    fasta_seq = ""
    pdb_seq = ""
    pdb_indexes = []
    answer = ""
    shift = 0
    index_list = []

    fasta_seq = getFastaSequance(fasta_file)
    pdb_seq, pdb_indexes = getPdbSequance(pdb_file, chain_id)

    print()
    print(fasta_seq)
    print(len(fasta_seq))
    print(pdb_seq)
    print(pdb_indexes)
    print(len(pdb_seq))

    print()
    print()

    if len(fasta_seq)==len(pdb_seq) and pdb_indexes[0]==1 and pdb_indexes[-1]==len(pdb_seq):
        print("FULLMATCH")
        answer = "FULLMATCH"
    elif len(fasta_seq)==len(pdb_seq) and pdb_indexes[-1]-pdb_indexes[0]+1==len(pdb_seq):
        print("Indexes are simply shifted by " + str(pdb_indexes[0]-1))
        answer = "SHIFT"
        shift = pdb_indexes[0]-1
    elif len(fasta_seq)==len(pdb_seq) and fasta_seq==pdb_seq:
        print("Number is messed up")
        print("Same length")
        answer = "INDEXED"
        for i in range(0, len(fasta_seq)):
            if i!=0 and pdb_indexes[i]<= pdb_indexes[i-1]:
                answer = "SKIP"
                index_list = []
                break
            index_list.append([ i, pdb_indexes[i], fasta_seq[i] ])
    else:
        alignments = pairwise2.align.globalms(fasta_seq, pdb_seq, 2, -1, -0.5, -0.1)
        #print alignments
        #print len(alignments)
        #print

        alist = getListOfValidAlignments(alignments, pdb_indexes)
        #print len(alist), alist

        if len(alist)==1:
            answer = "INDEXED"
            index_list = getIndexArray(alignments[alist[0]], pdb_indexes)
        elif len(alist)>1:
            answer = "SKIP"
        elif len(alist)==0:
            answer = "SKIP"
            #alignments = pairwise2.align.globalxx(fasta_seq, pdb_seq)
            #print
            #print alignments
                #print len(alignments)
            #print

            #alist2 = getListOfValidAlignments(alignments, pdb_indexes)
                #print len(alist2), alist2

            #if len(alist2)==1:
            #	answer = "INDEXED"
            #	index_list = getIndexArray(alignments[alist2[0]], pdb_indexes)
            #elif len(alist2)>1:
            #	answer = "SKIP"
            #elif len(alist2)==0:
            #	answer = "SKIP"

    out = open(index_file, 'w')
    out.write(answer)
    if answer=="SHIFT":
        out.write("\n")
        out.write(str(shift))
    elif answer=="INDEXED":
        for ind in index_list:
            out.write("\n")
            out.write(str(ind[0]+1))
            out.write(" ")
            out.write(str(ind[1]))
            out.write(" ")
            out.write(ind[2])
    out.close()


#fasta_file = sys.argv[1]
#pdb_id = sys.argv[2]
#pdb_file = pdb_id+".pdb"
#index_file = sys.argv[3]
#chain_id = sys.argv[4]

#writeIndexFile(fasta_file, pdb_file, index_file, chain_id)

In [38]:
import os

In [39]:
os.path.dirname(fasta_file)


Out[39]:
'/Users/weilu/Research/server/jun_2019/simluation_hybrid/frag_database/6e67A_HA/globularPart'

In [34]:
fasta_file = "/Users/weilu/Research/server/jun_2019/simluation_hybrid/frag_database/6e67A_HA/globularPart/5cxva.fasta"
pdb_file = "/Users/weilu/openmmawsem/PDBs/5CXV.pdb"
# pdb_file = "/Users/weilu/Research/server/jun_2019/simluation_hybrid/frag_database/6e67A_HA/globularPart/5cxv.pdb"
index_file = "/Users/weilu/openmmawsem/Indices/5cxva.index"
chain_id = "A"

fasta_seq = ""
pdb_seq = ""
pdb_indexes = []
answer = ""
shift = 0
index_list = []

fasta_seq = getFastaSequance(fasta_file)
pdb_seq, pdb_indexes = getPdbSequance(pdb_file, chain_id)


Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_0HK
Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_Y01
Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_EDO
Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_PGE
Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_EDO
Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_GOL
Unknown residue in /Users/weilu/openmmawsem/PDBs/5CXV with res_id H_EDO
/Users/weilu/anaconda3/envs/py36/lib/python3.6/site-packages/Bio/PDB/StructureBuilder.py:91: PDBConstructionWarning: WARNING: Chain A is discontinuous at line 4123.
  PDBConstructionWarning)
/Users/weilu/anaconda3/envs/py36/lib/python3.6/site-packages/Bio/PDB/StructureBuilder.py:91: PDBConstructionWarning: WARNING: Chain C is discontinuous at line 4218.
  PDBConstructionWarning)

In [37]:
pre = pdb_indexes[0]
for i in pdb_indexes[1:]:
    if i < pre:
        print(pre, i, "need reorder")
        break
    pre = i


1160 355 need reorder

In [31]:
pdb_indexes


Out[31]:
[20,
 21,
 22,
 23,
 24,
 25,
 26,
 27,
 28,
 29,
 30,
 31,
 32,
 33,
 34,
 35,
 36,
 37,
 38,
 39,
 40,
 41,
 42,
 43,
 44,
 45,
 46,
 47,
 48,
 49,
 50,
 51,
 52,
 53,
 54,
 55,
 56,
 57,
 58,
 59,
 60,
 61,
 62,
 63,
 64,
 65,
 66,
 67,
 68,
 69,
 70,
 71,
 72,
 73,
 74,
 75,
 76,
 77,
 78,
 79,
 80,
 81,
 82,
 83,
 84,
 85,
 86,
 87,
 88,
 89,
 90,
 91,
 92,
 93,
 94,
 95,
 96,
 97,
 98,
 99,
 100,
 101,
 102,
 103,
 104,
 105,
 106,
 107,
 108,
 109,
 110,
 111,
 112,
 113,
 114,
 115,
 116,
 117,
 118,
 119,
 120,
 121,
 122,
 123,
 124,
 125,
 126,
 127,
 128,
 129,
 130,
 131,
 132,
 133,
 134,
 135,
 136,
 137,
 138,
 139,
 140,
 141,
 142,
 143,
 144,
 145,
 146,
 147,
 148,
 149,
 150,
 151,
 152,
 153,
 154,
 155,
 156,
 157,
 158,
 159,
 160,
 161,
 162,
 163,
 164,
 165,
 166,
 167,
 168,
 169,
 170,
 171,
 172,
 173,
 174,
 175,
 176,
 177,
 178,
 179,
 180,
 181,
 182,
 183,
 184,
 185,
 186,
 187,
 188,
 189,
 190,
 191,
 192,
 193,
 194,
 195,
 196,
 197,
 198,
 199,
 200,
 201,
 202,
 203,
 204,
 205,
 206,
 207,
 208,
 209,
 210,
 211,
 212,
 213,
 214,
 215,
 216,
 217,
 218,
 1001,
 1002,
 1003,
 1004,
 1005,
 1006,
 1007,
 1008,
 1009,
 1010,
 1011,
 1012,
 1013,
 1014,
 1015,
 1016,
 1017,
 1018,
 1019,
 1020,
 1021,
 1022,
 1023,
 1024,
 1025,
 1026,
 1027,
 1028,
 1029,
 1030,
 1031,
 1032,
 1033,
 1034,
 1035,
 1036,
 1037,
 1038,
 1039,
 1040,
 1041,
 1042,
 1043,
 1044,
 1045,
 1046,
 1047,
 1048,
 1049,
 1050,
 1051,
 1052,
 1053,
 1054,
 1055,
 1056,
 1057,
 1058,
 1059,
 1060,
 1061,
 1062,
 1063,
 1064,
 1065,
 1066,
 1067,
 1068,
 1069,
 1070,
 1071,
 1072,
 1073,
 1074,
 1075,
 1076,
 1077,
 1078,
 1079,
 1080,
 1081,
 1082,
 1083,
 1084,
 1085,
 1086,
 1087,
 1088,
 1089,
 1090,
 1091,
 1092,
 1093,
 1094,
 1095,
 1096,
 1097,
 1098,
 1099,
 1100,
 1101,
 1102,
 1103,
 1104,
 1105,
 1106,
 1107,
 1108,
 1109,
 1110,
 1111,
 1112,
 1113,
 1114,
 1115,
 1116,
 1117,
 1118,
 1119,
 1120,
 1121,
 1122,
 1123,
 1124,
 1125,
 1126,
 1127,
 1128,
 1129,
 1130,
 1131,
 1132,
 1133,
 1134,
 1135,
 1136,
 1137,
 1138,
 1139,
 1140,
 1141,
 1142,
 1143,
 1144,
 1145,
 1146,
 1147,
 1148,
 1149,
 1150,
 1151,
 1152,
 1153,
 1154,
 1155,
 1156,
 1157,
 1158,
 1159,
 1160,
 355,
 356,
 357,
 358,
 359,
 360,
 361,
 362,
 363,
 364,
 365,
 366,
 367,
 368,
 369,
 370,
 371,
 372,
 373,
 374,
 375,
 376,
 377,
 378,
 379,
 380,
 381,
 382,
 383,
 384,
 385,
 386,
 387,
 388,
 389,
 390,
 391,
 392,
 393,
 394,
 395,
 396,
 397,
 398,
 399,
 400,
 401,
 402,
 403,
 404,
 405,
 406,
 407,
 408,
 409,
 410,
 411,
 412,
 413,
 414,
 415,
 416,
 417,
 418,
 419,
 420,
 421,
 422,
 423,
 424,
 425,
 426,
 427,
 428,
 429,
 430,
 431,
 432,
 433,
 434,
 435,
 436,
 437,
 438,
 439]

In [22]:
print()
print(fasta_seq)
print(len(fasta_seq))
print(pdb_seq)
print(pdb_indexes)
print(len(pdb_seq))

print()
print()

if len(fasta_seq)==len(pdb_seq) and pdb_indexes[0]==1 and pdb_indexes[-1]==len(pdb_seq):
    print("FULLMATCH")
    answer = "FULLMATCH"
elif len(fasta_seq)==len(pdb_seq) and pdb_indexes[-1]-pdb_indexes[0]+1==len(pdb_seq):
    print("Indexes are simply shifted by " + str(pdb_indexes[0]-1))
    answer = "SHIFT"
    shift = pdb_indexes[0]-1
elif len(fasta_seq)==len(pdb_seq) and fasta_seq==pdb_seq:
    print("Number is messed up")
    print("Same length")
    answer = "INDEXED"
    for i in range(0, len(fasta_seq)):
        if i!=0 and pdb_indexes[i]<= pdb_indexes[i-1]:
            answer = "SKIP"
            index_list = []
            break
        index_list.append([ i, pdb_indexes[i], fasta_seq[i] ])
else:
    alignments = pairwise2.align.globalms(fasta_seq, pdb_seq, 2, -1, -0.5, -0.1)
    #print alignments
    #print len(alignments)
    #print

    alist = getListOfValidAlignments(alignments, pdb_indexes)
    #print len(alist), alist

    if len(alist)==1:
        answer = "INDEXED"
        index_list = getIndexArray(alignments[alist[0]], pdb_indexes)
    elif len(alist)>1:
        answer = "SKIP"
    elif len(alist)==0:
        answer = "SKIP"


MKTIIALSYIFCLVFADYKDDDDAAAQTSAPPAVSPQITVLAPGKGPWQVAFIGITTGLLSLATVTGNLLVLISFKVNTELKTVNNYFLLSLACADLIIGTFSMNLYTTYLLMGHWALGTLACDLWLALDYVASQASVMNLLLISFDRYFSVTRPLSYRAKRTPRRAALMIGLAWLVSFVLWAPAILFWQYLVGERTVLAGQCYIQFLSQPIITFGTAMAAFYLPVTVMCTLYWRIYRETENRNIFEMLRIDEGLRLKIYKDTEGYYTIGIGHLLTKSPSLNAAKSELDKAIGRNTNGVITKDEAEKLFNQDVDAAVRGILRNAKLKPVYDSLDAVRRAALINMVFQMGETGVAGFTNSLRMLQQKRWDEAAVNLAKSRWYNQTPNRAKRVITTFRTGTWDAYFSLVKEKKAARTLSAILLAFILTWTPYNIMVLVSTFCKDCVPETLWELGYWLCYVNSTINPMCYALCNKAFRDTFRLLLLCRWDKRRWRKIPKRPGSVHRTPSRQCHHHHHH
515
KGPWQVAFIGITTGLLSLATVTGNLLVLISFKVNTELKTVNNYFLLSLACADLIIGTFSMNLYTTYLLMGHWALGTLACDLWLALDYVASQASVMNLLLISFDRYFSVTRPLSYRAKRTPRRAALMIGLAWLVSFVLWAPAILFWQYLVGERTVLAGQCYIQFLSQPIITFGTAMAAFYLPVTVMCTLYWRIYRETENRNIFEMLRIDEGLRLKIYKDTEGYYTIGIGHLLTKSPSLNAAKSELDKAIGRNTNGVITKDEAEKLFNQDVDAAVRGILRNAKLKPVYDSLDAVRRAALINMVFQMGETGVAGFTNSLRMLQQKRWDEAAVNLAKSRWYNQTPNRAKRVITTFRTGTWDAYFSLVKEKKAARTLSAILLAFILTWTPYNIMVLVSTFCKDCVPETLWELGYWLCYVNSTINPMCYALCNKAFRDTFRLLLLCRWDK
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444]
444



In [23]:
alignments


Out[23]:
[('MKTIIALSYIFCLVFADYKDDDDAAAQTSAPPAVSPQITVLAPGKGPWQVAFIGITTGLLSLATVTGNLLVLISFKVNTELKTVNNYFLLSLACADLIIGTFSMNLYTTYLLMGHWALGTLACDLWLALDYVASQASVMNLLLISFDRYFSVTRPLSYRAKRTPRRAALMIGLAWLVSFVLWAPAILFWQYLVGERTVLAGQCYIQFLSQPIITFGTAMAAFYLPVTVMCTLYWRIYRETENRNIFEMLRIDEGLRLKIYKDTEGYYTIGIGHLLTKSPSLNAAKSELDKAIGRNTNGVITKDEAEKLFNQDVDAAVRGILRNAKLKPVYDSLDAVRRAALINMVFQMGETGVAGFTNSLRMLQQKRWDEAAVNLAKSRWYNQTPNRAKRVITTFRTGTWDAYFSLVKEKKAARTLSAILLAFILTWTPYNIMVLVSTFCKDCVPETLWELGYWLCYVNSTINPMCYALCNKAFRDTFRLLLLCRWDKRRWRKIPKRPGSVHRTPSRQCHHHHHH',
  '--------------------------------------------KGPWQVAFIGITTGLLSLATVTGNLLVLISFKVNTELKTVNNYFLLSLACADLIIGTFSMNLYTTYLLMGHWALGTLACDLWLALDYVASQASVMNLLLISFDRYFSVTRPLSYRAKRTPRRAALMIGLAWLVSFVLWAPAILFWQYLVGERTVLAGQCYIQFLSQPIITFGTAMAAFYLPVTVMCTLYWRIYRETENRNIFEMLRIDEGLRLKIYKDTEGYYTIGIGHLLTKSPSLNAAKSELDKAIGRNTNGVITKDEAEKLFNQDVDAAVRGILRNAKLKPVYDSLDAVRRAALINMVFQMGETGVAGFTNSLRMLQQKRWDEAAVNLAKSRWYNQTPNRAKRVITTFRTGTWDAYFSLVKEKKAARTLSAILLAFILTWTPYNIMVLVSTFCKDCVPETLWELGYWLCYVNSTINPMCYALCNKAFRDTFRLLLLCRWDK---------------------------',
  880.0999999999995,
  0,
  515)]

In [24]:
alist = getListOfValidAlignments(alignments, pdb_indexes)

In [26]:
alist


Out[26]:
[0]

In [27]:
ialigns = []
i =0
alignment = alignments[i]
alseq_fasta = alignment[0]
alseq_pdb = alignment[1]

if len(alseq_fasta)!=len(alseq_pdb):
    print("Error using alignment too")
    print()
    exit()

last_i_pdb = -1
last_j = -1
i_pdb = 0
valid = True
for j in range(0, len(alseq_pdb)):
        if alseq_pdb[j]!='-':
#                                if last_i_pdb!=-1 and j - last_j > i_pdb - last_i_pdb:
            if last_i_pdb!=-1 and j - last_j != pdb_indexes[i_pdb] - pdb_indexes[last_i_pdb]:
                print(last_i_pdb, j, last_j, i_pdb, last_i_pdb, pdb_indexes[i_pdb], pdb_indexes[last_i_pdb])
                valid = False
                break
            last_i_pdb = i_pdb
            last_j = j
            i_pdb = i_pdb + 1
if valid:
        ialigns.append(i)

In [ ]: