Skip to content

Commit f0b2e23

Browse files
use before distance calculations
1 parent bdaadab commit f0b2e23

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

package/MDAnalysis/analysis/dssp/pydssp_numpy.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import numpy as np
1313

14-
from MDAnalysis.lib.distances import capped_distance
14+
from MDAnalysis.lib.distances import capped_distance, minimize_vectors
1515

1616
CONST_Q1Q2 = 0.084
1717
CONST_F = 332
@@ -195,16 +195,16 @@ def get_hbond_map(
195195
# We can reduce the need for a complete pairwise distance matrix by first searching for
196196
# candidate pairs within a certain distance cutoff and only computing the energy
197197
# for these relevant pairs rather than "potential" HBonds between far apart residues
198-
pairs = capped_distance(
198+
pairs, d_on = capped_distance(
199199
n_atoms,
200200
o_atoms,
201201
max_cutoff=HBOND_SEARCH_CUTOFF,
202-
return_distances=False,
203202
box=box,
204203
)
205204

206205
# Exclude local pairs (i, i), (i, i+1), (i, i+2) that are too close for SS HBonds
207-
pairs = pairs[abs(pairs[:, 0] - pairs[:, 1]) >= 2]
206+
local_mask = abs(pairs[:, 0] - pairs[:, 1]) >= 2
207+
pairs = pairs[local_mask]
208208

209209
# Exclude donor H absence (Proline)
210210
if donor_mask is not None:
@@ -216,10 +216,21 @@ def get_hbond_map(
216216
# still returning the same energy matrix that would have otherwise been made
217217
o_indices = pairs[:, 1]
218218
n_indices = pairs[:, 0]
219-
d_on = np.linalg.norm(o_atoms[o_indices] - n_atoms[n_indices], axis=-1)
220-
d_ch = np.linalg.norm(c_atoms[o_indices] - h_1[n_indices], axis=-1)
221-
d_oh = np.linalg.norm(o_atoms[o_indices] - h_1[n_indices], axis=-1)
222-
d_cn = np.linalg.norm(c_atoms[o_indices] - n_atoms[n_indices], axis=-1)
219+
220+
# d_on = d_on[local_mask]
221+
def _distances(x, y, box=None):
222+
if box is None:
223+
return np.linalg.norm(x[o_indices] - y[n_indices], axis=-1)
224+
else:
225+
return np.linalg.norm(
226+
minimize_vectors(x[o_indices] - y[n_indices], box=box),
227+
axis=-1,
228+
)
229+
230+
d_on = _distances(o_atoms, n_atoms, box)
231+
d_ch = _distances(c_atoms, h_1, box)
232+
d_oh = _distances(o_atoms, h_1, box)
233+
d_cn = _distances(c_atoms, n_atoms, box)
223234

224235
# electrostatic interaction energy
225236
# e[i, j] = e(CO_i) - e(NH_j)
@@ -285,7 +296,7 @@ def assign(
285296
286297
"""
287298
# get hydrogen bond map
288-
hbmap = get_hbond_map(coord, donor_mask=donor_mask)
299+
hbmap = get_hbond_map(coord, donor_mask=donor_mask, box=box)
289300
hbmap = np.swapaxes(hbmap, -1, -2) # convert into "i:C=O, j:N-H" form
290301

291302
# identify turn 3, 4, 5

0 commit comments

Comments
 (0)