Skip to content

Commit

Permalink
Merge branch 'prody:main' into prody-signint
Browse files Browse the repository at this point in the history
  • Loading branch information
karolamik13 authored Nov 16, 2024
2 parents 22ff338 + e20a87c commit 3dab901
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 22 deletions.
2 changes: 1 addition & 1 deletion prody/dynamics/clustenm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ def run(self, cutoff=15., n_modes=3, gamma=1., n_confs=50, rmsd=1.0,
self._sparse = kwargs.get('sparse', False)
self._kdtree = kwargs.get('kdtree', False)
self._turbo = kwargs.get('turbo', False)
self._nproc = kwargs.pop('nproc', None)
self._nproc = kwargs.pop('nproc', 0)
if kwargs.get('zeros', False):
LOGGER.warn('ClustENM cannot use zero modes so ignoring this kwarg')

Expand Down
Binary file added prody/proteins/hpbmodule/hpb_Python3.11/hpb.so
Binary file not shown.
Binary file added prody/proteins/hpbmodule/hpb_Python3.12/hpb.so
Binary file not shown.
100 changes: 80 additions & 20 deletions prody/proteins/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,11 @@ def calcChHydrogenBonds(atoms, **kwargs):

ChainsHBs = [ i for i in HBS_calculations if str(i[2]) != str(i[5]) ]
if not ChainsHBs:
ligand_name = list(set(atoms.select('all not protein and not ion').getResnames()))[0]
ChainsHBs = [ ii for ii in HBS_calculations if ii[0][:3] == ligand_name or ii[3][:3] == ligand_name ]

ligand_sel = atoms.select('all not protein and not ion')
if ligand_sel:
ligand_name = list(set(ligand_sel.getResnames()))[0]
ChainsHBs = [ ii for ii in HBS_calculations if ii[0][:3] == ligand_name or ii[3][:3] == ligand_name ]

return ChainsHBs


Expand Down Expand Up @@ -4398,8 +4400,43 @@ def saveInteractionsPDB(self, **kwargs):
writePDB('filename', atoms, **kw)
LOGGER.info('PDB file saved.')


def getFrequentInteractors(self, contacts_min=3):

def getInteractors(self, residue_name):
""" Provide information about interactions for a particular residue
:arg residue_name: name of a resiude
example: LEU234A, where A is a chain name
:type residue_name: str
"""

atoms = self._atoms
interactions = self._interactions

InteractionsMap = np.empty([atoms.select('name CA').numAtoms(),atoms.select('name CA').numAtoms()], dtype=object)
resIDs = list(atoms.select('name CA').getResnums())
resChIDs = list(atoms.select('name CA').getChids())
resIDs_with_resChIDs = list(zip(resIDs, resChIDs))
interaction_type = ['hb','sb','rb','ps','pc','hp','dibs']
ListOfInteractions = []

for nr,i in enumerate(interactions):
if i != []:
for ii in i:
m1 = resIDs_with_resChIDs.index((int(ii[0][3:]),ii[2]))
m2 = resIDs_with_resChIDs.index((int(ii[3][3:]),ii[5]))
ListOfInteractions.append(interaction_type[nr]+':'+ii[0]+ii[2]+'-'+ii[3]+ii[5])

aa_ListOfInteractions = []
for i in ListOfInteractions:
inter = i.split(":")[1:][0]
if inter.split('-')[0] == residue_name or inter.split('-')[1] == residue_name:
LOGGER.info(i)
aa_ListOfInteractions.append(i)

return aa_ListOfInteractions


def getFrequentInteractors(self, contacts_min=2):
"""Provide a list of residues with the most frequent interactions based
on the following interactions:
(1) Hydrogen bonds (hb)
Expand All @@ -4411,7 +4448,7 @@ def getFrequentInteractors(self, contacts_min=3):
(7) Disulfide bonds (disb)
:arg contacts_min: Minimal number of contacts which residue may form with other residues,
by default 3.
by default 2.
:type contacts_min: int """

atoms = self._atoms
Expand All @@ -4428,36 +4465,59 @@ def getFrequentInteractors(self, contacts_min=3):
for ii in i:
m1 = resIDs_with_resChIDs.index((int(ii[0][3:]),ii[2]))
m2 = resIDs_with_resChIDs.index((int(ii[3][3:]),ii[5]))
InteractionsMap[m1][m2] = interaction_type[nr]+':'+ii[0]+ii[2]+'-'+ii[3]+ii[5]

if InteractionsMap[m1][m2] is None:
InteractionsMap[m1][m2] = []

InteractionsMap[m1][m2].append(interaction_type[nr] + ':' + ii[0] + ii[2] + '-' + ii[3] + ii[5])

ListOfInteractions = [ list(filter(None, InteractionsMap[:,j])) for j in range(len(interactions[0])) ]
ListOfInteractions = list(filter(lambda x : x != [], ListOfInteractions))
ListOfInteractions = [k for k in ListOfInteractions if len(k) >= contacts_min ]
ListOfInteractions_list = [ (i[0].split('-')[-1], [ j.split('-')[0] for j in i]) for i in ListOfInteractions ]
LOGGER.info('The most frequent interactions between:')
for res in ListOfInteractions_list:
ListOfInteractions = [list(filter(None, [row[j] for row in InteractionsMap])) for j in range(len(InteractionsMap[0]))]
ListOfInteractions = list(filter(lambda x: x != [], ListOfInteractions))
ListOfInteractions_flattened = [j for sublist in ListOfInteractions for j in sublist]

swapped_ListOfInteractions_list = []
for interaction_group in ListOfInteractions_flattened:
swapped_group = []
for interaction in interaction_group:
interaction_type, pair = interaction.split(':')
swapped_pair = '-'.join(pair.split('-')[::-1])
swapped_group.append("{}:{}".format(interaction_type, swapped_pair))
swapped_ListOfInteractions_list.append(swapped_group)

doubleListOfInteractions_list = ListOfInteractions_flattened+swapped_ListOfInteractions_list
ListOfInteractions_list = [(i[0].split('-')[-1], [j.split('-')[0] for j in i]) for i in doubleListOfInteractions_list]

merged_dict = {}
for aa, ii in ListOfInteractions_list:
if aa in merged_dict:
merged_dict[aa].extend(ii)
else:
merged_dict[aa] = ii

ListOfInteractions_list = [(key, value) for key, value in merged_dict.items()]
ListOfInteractions_list2 = [k for k in ListOfInteractions_list if len(k[-1]) >= contacts_min]

for res in ListOfInteractions_list2:
LOGGER.info('{0} <---> {1}'.format(res[0], ' '.join(res[1])))

LOGGER.info('Legend: hb-hydrogen bond, sb-salt bridge, rb-repulsive ionic bond, ps-Pi stacking interaction,'
'pc-Cation-Pi interaction, hp-hydrophobic interaction, dibs-disulfide bonds')
LOGGER.info('\nLegend: hb-hydrogen bond, sb-salt bridge, rb-repulsive ionic bond, ps-Pi stacking interaction,'
'\npc-Cation-Pi interaction, hp-hydrophobic interaction, dibs-disulfide bonds')

try:
from toolz.curried import count
except ImportError:
LOGGER.warn('This function requires the module toolz')
return

LOGGER.info('The biggest number of interactions: {}'.format(max(map(count, ListOfInteractions))))

return ListOfInteractions_list
return ListOfInteractions_list2


def showFrequentInteractors(self, cutoff=5, **kwargs):
def showFrequentInteractors(self, cutoff=4, **kwargs):
"""Plots regions with the most frequent interactions.
:arg cutoff: minimal score per residue which will be displayed.
If cutoff value is to big, top 30% with the higest values will be returned.
Default is 5.
Default is 4.
:type cutoff: int, float
Nonstandard resiudes can be updated in a following way:
Expand Down
2 changes: 1 addition & 1 deletion prody/tests/proteins/test_insty.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def testImportHpb(self):
except ImportError:
imported_hpb = False

if sys.version_info[1] < 11:
if sys.version_info[1] < 13:
self.assertTrue(imported_hpb)
else:
self.assertFalse(imported_hpb)
Expand Down
2 changes: 2 additions & 0 deletions prody/utilities/catchall.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ def showMatrix(matrix, x_array=None, y_array=None, **kwargs):
im = ax3.imshow(matrix, aspect=aspect, vmin=vmin, vmax=vmax,
norm=norm, cmap=cmap, origin=origin, **kwargs)
else:
zeros_matrix = np.zeros(matrix.shape)
im = ax3.imshow(zeros_matrix, vmin=-1, vmax=1, cmap='seismic')
plot_list = []
for rows,cols in zip(np.where(matrix!=0)[0],np.where(matrix!=0)[1]):
plot_list.append([cols,rows,matrix[rows,cols]])
Expand Down

0 comments on commit 3dab901

Please sign in to comment.