Skip to content

Commit 158c5fd

Browse files
committed
fix style and format issues
1 parent cd8b39c commit 158c5fd

10 files changed

Lines changed: 98 additions & 117 deletions

pdb2sql/StructureSimilarity.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class StructureSimilarity(object):
99

1010
def __init__(self,decoy,ref,verbose=False):
11-
'''Compute structure similarity between two structures.
11+
"""Compute structure similarity between two structures.
1212
1313
This class allows to compute the i-RMSD, L-RMSD, Fnat and DockQ
1414
score of a given conformation.
@@ -48,7 +48,7 @@ def __init__(self,decoy,ref,verbose=False):
4848
... ref_pairs='1AK4.ref_pairs')
4949
>>> dockQ = sim.compute_DockQScore(Fnat_fast,
5050
... lrmsd_fast,irmsd_fast)
51-
'''
51+
"""
5252

5353
self.decoy = decoy
5454
self.ref = ref
@@ -68,7 +68,7 @@ def __init__(self,decoy,ref,verbose=False):
6868

6969
# compute the L-RMSD
7070
def compute_lrmsd_fast(self,lzone=None,method='svd',check=True):
71-
'''Fast routine to compute the L-RMSD.
71+
"""Fast routine to compute the L-RMSD.
7272
7373
L-RMSD is computed by aligning the longest chain of the decoy to
7474
the one of the reference and computing the RMSD of the shortest
@@ -91,7 +91,7 @@ def compute_lrmsd_fast(self,lzone=None,method='svd',check=True):
9191
9292
See also:
9393
:meth:`compute_lrmsd_pdb2sql`
94-
'''
94+
"""
9595

9696
# create/read the lzone file
9797
if lzone is None:
@@ -257,8 +257,6 @@ def compute_irmsd_fast(self,izone=None,method='svd',cutoff=10,check=True):
257257
data_decoy = self.get_data_zone_backbone(self.decoy,resData,return_not_in_zone=False)
258258
data_ref = self.get_data_zone_backbone(self.ref,resData,return_not_in_zone=False)
259259

260-
atom_decoy = [ data[:3] for data in data_decoy]
261-
atom_ref = [ data[:3] for data in data_ref ]
262260
atom_common = data_ref.intersection(data_decoy)
263261
xyz_contact_decoy = self._get_xyz(self.decoy, atom_common)
264262
xyz_contact_ref = self._get_xyz(self.ref, atom_common)
@@ -301,7 +299,7 @@ def compute_izone(self,cutoff=10.0,save_file=True,filename=None):
301299
contact_ref = sql_ref.get_contact_atoms(cutoff=cutoff,extend_to_residue=True)
302300

303301
index_contact_ref = []
304-
for k,v in contact_ref.items():
302+
for _,v in contact_ref.items():
305303
index_contact_ref += v
306304

307305
# get the xyz and atom identifier of the decoy contact atoms
@@ -415,7 +413,7 @@ def compute_fnat_fast(self,cutoff=5):
415413
nCommon += 1
416414
nTotal += 1
417415
else:
418-
msg = f'\t FNAT: not find residue: {resA} in {decoy_name}'
416+
msg = f'\t FNAT: not find residue: {resA}'
419417
warnings.warn(msg)
420418

421419
# normalize
@@ -935,10 +933,6 @@ def get_data_zone_backbone(pdb_file,resData,return_not_in_zone=False):
935933
resSeq = int(line[22:26])
936934
name = line[12:16].strip()
937935

938-
x = float(line[30:38])
939-
y = float(line[38:46])
940-
z = float(line[46:54])
941-
942936
backbone = ['C','CA','N','O']
943937
if chainID in resData.keys():
944938

@@ -1228,7 +1222,7 @@ def get_rotation_matrix_Kabsh(P,Q):
12281222
A = np.dot(P.T,Q)/npts
12291223

12301224
# SVD the matrix
1231-
V,S,W = np.linalg.svd(A)
1225+
V,_,W = np.linalg.svd(A)
12321226

12331227
# the W matrix returned here is
12341228
# already its transpose

pdb2sql/interface.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import numpy as np
32
import itertools
43
import warnings
@@ -7,10 +6,8 @@
76

87
class interface(pdb2sql):
98

10-
# def __init__(self, pdb):
119
def __init__(self, pdb, **kwargs):
12-
'''Identify interface between protein chains.'''
13-
10+
"""Identify interface between protein chains."""
1411
super().__init__(pdb, **kwargs)
1512

1613
##########################################################################
@@ -29,7 +26,7 @@ def get_contact_atoms(
2926
only_backbone_atoms=False,
3027
excludeH=False,
3128
return_contact_pairs=False):
32-
"""get rowIDs of contact atoms.
29+
"""Get rowIDs of contact atoms.
3330
3431
Args:
3532
cutoff (float): distance cutoff for calculating contact.
@@ -188,7 +185,7 @@ def get_contact_residues(
188185
excludeH=False,
189186
only_backbone_atoms=False,
190187
return_contact_pairs=False):
191-
"""get contact residues represented with (chain,resSeq, resname).
188+
"""Get contact residues represented with (chain,resSeq, resname).
192189
193190
Args:
194191
cutoff (float): distance cutoff for contact calculation

pdb2sql/pdb2sqlAlchemy.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from sqlalchemy import *
2-
from sqlalchemy import Column, ForeignKey, Integer, String
1+
from sqlalchemy import Column, ForeignKey, Integer, String, Float
32
from sqlalchemy.ext.declarative import declarative_base
4-
from sqlalchemy.orm import relationship
53
from sqlalchemy import create_engine
64
from sqlalchemy.schema import Sequence
75
from sqlalchemy.orm import sessionmaker
@@ -13,7 +11,7 @@
1311

1412

1513
class ATOM(Base):
16-
'''SQLAlchemy object for atoms.'''
14+
"""SQLAlchemy object for atoms."""
1715

1816
__tablename__ = 'ATOM'
1917
rowID = Column(Integer, primary_key=True)
@@ -41,16 +39,16 @@ def __init__(
4139
sqlfile=None,
4240
fix_chainID=False,
4341
verbose=False):
44-
'''Use sqlAlchemy to load the database.'''
42+
"""Use sqlAlchemy to load the database."""
4543
super().__init__(pdbfile, sqlfile, fix_chainID, verbose)
4644
self._create_sql()
4745

4846
def _create_sql(self):
4947

5048
# sqlalchemy init
51-
self.engine = create_engine('sqlite:///:memory:')
52-
Base.metadata.create_all(self.engine)
53-
DBSession = sessionmaker(bind=self.engine)
49+
self.conn = create_engine('sqlite:///:memory:')
50+
Base.metadata.create_all(self.conn)
51+
DBSession = sessionmaker(bind=self.conn)
5452
self.session = DBSession()
5553

5654
# read the pdb file a pure python way
@@ -82,11 +80,11 @@ def _create_sql(self):
8280
del_copy['chainID'] = [72, 73]
8381
if line[del_copy['chainID'][0]] == ' ':
8482
raise ValueError('chainID not found sorry')
85-
_check_format_ = False
83+
_check_format = False
8684

8785
# browse all attribute of each atom
8886
at = {}
89-
for ik, (colname, coltype) in enumerate(self.col.items()):
87+
for _, (colname, coltype) in enumerate(self.col.items()):
9088

9189
# get the piece of data
9290
if colname in del_copy.keys():
@@ -126,7 +124,8 @@ def _create_sql(self):
126124
fi.close()
127125

128126
def get(self, attribute=None, **kwargs):
129-
'''Exectute a simple SQL query that extracts values of attributes for certain condition.
127+
"""Exectute a simple SQL query that extracts values of attributes for
128+
certain condition.
130129
131130
Args :
132131
attribute (str) : attribute to retreive eg : ['x','y,'z'], 'xyz', 'resSeq'
@@ -139,7 +138,7 @@ def get(self, attribute=None, **kwargs):
139138
140139
Example :
141140
>>> db.get('x,y,z',chainID='A',no_name=['H']")
142-
'''
141+
"""
143142

144143
# parse the commas in the attribute
145144
if attribute is not None:
@@ -223,7 +222,7 @@ def get(self, attribute=None, **kwargs):
223222
1 if attribute == 'rowID' else atom.__dict__[attribute] for atom in atom_list]
224223

225224
def update(self, attribute, values, **kwargs):
226-
'''Update the database.
225+
"""Update the database.
227226
228227
Args:
229228
attribute (str) : string of attribute names eg. ['x','y,'z'], 'xyz', 'resSeq'
@@ -232,7 +231,7 @@ def update(self, attribute, values, **kwargs):
232231
to the number of attributes and atoms selected
233232
234233
kwargs : selection arguments eg : name = ['CA','O'], chainID = 'A', no_name = ['H']
235-
'''
234+
"""
236235

237236
# parse the commas in the attribute
238237
if ',' in attribute:

pdb2sql/pdb2sql_base.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import sqlite3
2-
import subprocess as sp
31
import os
4-
import numpy as np
52
from time import time
63

74

@@ -13,7 +10,7 @@ def __init__(
1310
sqlfile=None,
1411
fix_chainID=False,
1512
verbose=False):
16-
'''Base class for the definition of sql database.
13+
"""Base class for the definition of sql database.
1714
1815
Args:
1916
pdbfile (str, list(str/bytes), ndarray) : name of pdbfile or
@@ -23,8 +20,7 @@ def __init__(
2320
fix_chainID (bool, optinal): check if the name of the chains
2421
are A,B,C, .... and fix it if not.
2522
verbose (bool): probably print stuff
26-
'''
27-
23+
"""
2824
self.pdbfile = pdbfile
2925
self.sqlfile = sqlfile
3026
self.fix_chainID = fix_chainID
@@ -89,7 +85,7 @@ def get(self, atnames, **kwargs):
8985
raise NotImplementedError()
9086

9187
def get_xyz(self, **kwargs):
92-
'''Shortcut to get the xyz coordinates.'''
88+
"""Shortcut to get the xyz coordinates."""
9389
return self.get('x,y,z', **kwargs)
9490

9591
def get_residues(self, **kwargs):
@@ -121,19 +117,19 @@ def update(self, attribute, values, **kwargs):
121117
raise NotImplementedError()
122118

123119
def update_xyz(self, xyz, **kwargs):
124-
'''Update the xyz coordinates.'''
120+
"""Update the xyz coordinates."""
125121
self.update('x,y,z', xyz, **kwargs)
126122

127123
def update_column(self, colname, values, index=None):
128-
'''Update a single column.'''
124+
"""Update a single column."""
129125
raise NotImplementedError()
130126

131127
def add_column(self, colname, coltype='FLOAT', default=0):
132-
'''Add a new column to the ATOM table.'''
128+
"""Add a new column to the ATOM table."""
133129
raise NotImplementedError()
134130

135131
def exportpdb(self, fname, append=False, periodic=False, **kwargs):
136-
'''Export a PDB file with kwargs selection.'''
132+
"""Export a PDB file with kwargs selection."""
137133

138134
if append:
139135
f = open(fname, 'a')
@@ -147,7 +143,7 @@ def exportpdb(self, fname, append=False, periodic=False, **kwargs):
147143
f.close()
148144

149145
def sql2pdb(self, **kwargs):
150-
"""Convert SQL data to PDB formatted lines
146+
"""Convert SQL data to PDB formatted lines.
151147
152148
Returns:
153149
list: pdb-format lines
@@ -181,7 +177,8 @@ def sql2pdb(self, **kwargs):
181177
return pdb
182178

183179
def _format_atomname(self, data):
184-
"""Format atom name to align with PDB reqireuments:
180+
"""Format atom name to align with PDB reqireuments.
181+
185182
- alignment of one-letter atom name starts at column 14,
186183
- while two-letter atom name such as FE starts at column 13.
187184

0 commit comments

Comments
 (0)