Skip to content

Commit dd5a49c

Browse files
committed
fix irmsd and lrmsd pdb2ql routine
1 parent e16bddb commit dd5a49c

2 files changed

Lines changed: 44 additions & 23 deletions

File tree

pdb2sql/StructureSimilarity.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ def compute_irmsd_fast(
254254
# read the izone file
255255
if izone is None:
256256
resData = self.compute_izone(cutoff, save_file=False)
257-
# elif not os.path.isfile(izone):
258-
# resData = self.compute_izone(cutoff,save_file=True,filename=izone)
259257
else:
260258
resData = self.read_zone(izone)
261259

@@ -501,37 +499,40 @@ def compute_lrmsd_pdb2sql(self, exportpath=None, method='svd'):
501499
backbone = ['CA', 'C', 'N', 'O']
502500

503501
# create the sql
504-
sql_decoy = pdb2sql(
505-
self.decoy, sqlfile='decoy.db', fix_chainID=True)
506-
sql_ref = pdb2sql(
507-
self.ref, sqlfile='ref.db', fix_chainID=True)
502+
sql_decoy = pdb2sql(self.decoy, sqlfile='decoy.db')
503+
sql_ref = pdb2sql(self.ref, sqlfile='ref.db')
504+
505+
# get the chains
506+
chains_decoy = sql_decoy.get_chains()
507+
chains_ref = sql_ref.get_chains()
508+
509+
if chains_decoy != chains_ref:
510+
raise ValueError(
511+
'Chains are different in decoy and reference structure')
512+
513+
chain1 = chains_decoy[0]
514+
chain2 = chains_decoy[1]
508515

509516
# extract the pos of chains A
510517
xyz_decoy_A = np.array(
511-
sql_decoy.get(
512-
'x,y,z',
513-
chainID='A',
514-
name=backbone))
518+
sql_decoy.get('x,y,z', chainID=chain1, name=backbone))
515519
xyz_ref_A = np.array(sql_ref.get(
516-
'x,y,z', chainID='A', name=backbone))
520+
'x,y,z', chainID=chain1, name=backbone))
517521

518522
# extract the pos of chains B
519523
xyz_decoy_B = np.array(
520-
sql_decoy.get(
521-
'x,y,z',
522-
chainID='B',
523-
name=backbone))
524+
sql_decoy.get('x,y,z', chainID=chain2, name=backbone))
524525
xyz_ref_B = np.array(sql_ref.get(
525-
'x,y,z', chainID='B', name=backbone))
526+
'x,y,z', chainID=chain2, name=backbone))
526527

527528
# check the lengthes
528529
if len(xyz_decoy_A) != len(xyz_ref_A):
529530
xyz_decoy_A, xyz_ref_A = self.get_identical_atoms(
530-
sql_decoy, sql_ref, 'A')
531+
sql_decoy, sql_ref, chain1)
531532

532533
if len(xyz_decoy_B) != len(xyz_ref_B):
533534
xyz_decoy_B, xyz_ref_B = self.get_identical_atoms(
534-
sql_decoy, sql_ref, 'B')
535+
sql_decoy, sql_ref, chain2)
535536

536537
# detect which chain is the longest
537538
nA, nB = len(xyz_decoy_A), len(xyz_decoy_B)
@@ -688,14 +689,26 @@ def compute_irmsd_pdb2sql(
688689
"""
689690

690691
# create thes sql
691-
sql_decoy = interface(self.decoy, fix_chainID=True)
692-
sql_ref = interface(self.ref, fix_chainID=True)
692+
sql_decoy = interface(self.decoy)
693+
sql_ref = interface(self.ref)
694+
695+
# get the chains
696+
chains_decoy = sql_decoy.get_chains()
697+
chains_ref = sql_ref.get_chains()
698+
699+
if chains_decoy != chains_ref:
700+
raise ValueError(
701+
'Chains are different in decoy and reference structure')
693702

694703
# get the contact atoms
695704
if izone is None:
705+
696706
contact_ref = sql_ref.get_contact_atoms(
697707
cutoff=cutoff,
698-
extend_to_residue=True)
708+
extend_to_residue=True,
709+
chain1=chains_ref[0],
710+
chain2=chains_decoy[1])
711+
699712
index_contact_ref = []
700713
for v in contact_ref.values():
701714
index_contact_ref += v

pdb2sql/interface.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import warnings
44
from .pdb2sqlcore import pdb2sql
55

6+
67
class interface(pdb2sql):
78

89
def __init__(self, pdb, **kwargs):
@@ -73,6 +74,12 @@ def get_contact_atoms(
7374
else:
7475
chainIDs = [chain1, chain2]
7576

77+
chains = self.get_chains()
78+
for c in chainIDs:
79+
if c not in chains:
80+
raise ValueError(
81+
'chain %s not found in the structure' % c)
82+
7683
xyz = dict()
7784
index = dict()
7885
resName = dict()
@@ -265,7 +272,8 @@ def get_contact_residues(
265272
residue_contact_pairs[data1] = set()
266273

267274
# get the res info of the atom in the other chain
268-
data2 = self.get('chainID,resSeq,resName', rowID=atoms2)
275+
data2 = self.get(
276+
'chainID,resSeq,resName', rowID=atoms2)
269277

270278
# store that in the dict without double
271279
for resData in data2:
@@ -300,4 +308,4 @@ def get_contact_residues(
300308
residue_contact[chain] = sorted(
301309
set([tuple(resData) for resData in data[chain]]))
302310

303-
return residue_contact
311+
return residue_contact

0 commit comments

Comments
 (0)