Skip to content

Commit 73817ac

Browse files
Replace numpy in1d usage with numpy.isin (#503)
Replaced numpy in1d() with isin()
1 parent 008674d commit 73817ac

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pytim/interface.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from . import utilities
99
from scipy.spatial import cKDTree
1010

11+
from .patches import patchNumpy_isin
12+
13+
patchNumpy_isin()
14+
1115

1216
class Interface(object):
1317
""" The Interface metaclass. Classes for interfacial determination
@@ -670,8 +674,8 @@ def __():
670674
... #interface.writepdb(method.__name__+'.pdb') ; # debug
671675
... cond = (ref_ind == ind )
672676
... if np.all(cond) == False:
673-
... miss1 = (np.in1d(ref_ind,ind)==False).sum()
674-
... miss2 = (np.in1d(ind,ref_ind)==False).sum()
677+
... miss1 = (~np.isin(ref_ind, ind)).sum()
678+
... miss2 = (~np.isin(ind, ref_ind)).sum()
675679
... percent = (miss1 + miss2)*0.5/len(ref_ind) * 100.
676680
... if percent > 2: # this should be 0 for ITIM, and < 5
677681
... # for GITIM, with this config+alpha
@@ -707,8 +711,8 @@ def __():
707711
... #interface.writepdb(method.__name__+'.pdb') ; # debug
708712
... cond = (ref_ind == ind )
709713
... if np.all(cond) == False:
710-
... miss1 = (np.in1d(ref_ind,ind)==False).sum()
711-
... miss2 = (np.in1d(ind,ref_ind)==False).sum()
714+
... miss1 = (~np.isin(ref_ind, ind)).sum()
715+
... miss2 = (~np.isin(ind, ref_ind)).sum()
712716
... percent = (miss1 + miss2)*0.5/len(ref_ind) * 100.
713717
... if percent > 4 : # should be ~ 4 % for this system
714718
... print (miss1+miss2)

pytim/itim.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
from .sanity_check import SanityCheck
2222

2323
from .interface import Interface
24-
from .patches import patchTrajectory, patchOpenMM, patchMDTRAJ
24+
from .patches import patchTrajectory, patchOpenMM, patchMDTRAJ, patchNumpy_isin
2525

26+
patchNumpy_isin()
2627

2728
class ITIM(Interface):
2829
""" Identifies interfacial molecules at macroscopically flat interfaces.
@@ -278,7 +279,7 @@ def _append_layers(self, uplow, layer, layers):
278279
# NOTE that from MDAnalysis 0.16, .ids runs from 1->N
279280
# (was 0->N-1 in 0.15), we use now .indices
280281
indices = np.flatnonzero(
281-
np.in1d(self.cluster_group.atoms.indices,
282+
np.isin(self.cluster_group.atoms.indices,
282283
inlayer_group.atoms.indices))
283284
# and update the tagged, sorted atoms
284285
self._seen[uplow][indices] = layer + 1

pytim/patches.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding: utf-8 -*-
22
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
33
from __future__ import print_function
4+
import numpy as np
5+
def patchNumpy_isin():
6+
try: np.isin
7+
except AttributeError: np.isin = np.in1d
48

59
def patchTrajectory(trajectory, interface):
610
""" Patch the MDAnalysis trajectory class

0 commit comments

Comments
 (0)