def _check_point(self, meth, periodic): sel = Parser.parse('point 5.0 5.0 5.0 3.0', self.u.atoms) sel = self.choosemeth(sel, meth, periodic) result = sel.apply(self.u.atoms) box = self.u.dimensions if periodic else None d = distance_array(np.array([[5.0, 5.0, 5.0]], dtype=np.float32), self.u.atoms.positions, box=box) ref = set(np.where(d < 3.0)[1]) assert_(ref == set(result.indices))
def test_spherical_zone(self, u, meth, periodic): sel = Parser.parse('sphzone 5.0 resid 1', u.atoms) sel = self.choosemeth(sel, meth, periodic) result = sel.apply(u.atoms) r1 = u.select_atoms('resid 1') box = u.dimensions if periodic else None cog = r1.center_of_geometry(pbc=periodic).reshape(1, 3) d = distance_array(u.atoms.positions, cog, box=box) ref = set(np.where(d < 5.0)[0]) assert ref == set(result.indices)
def _check_spherical_layer(self, meth, periodic): sel = Parser.parse('sphlayer 2.4 6.0 resid 1', self.u.atoms) sel = self.choosemeth(sel, meth, periodic) result = sel.apply(self.u.atoms) r1 = self.u.select_atoms('resid 1') cog = r1.center_of_geometry().reshape(1, 3) box = self.u.dimensions if periodic else None d = distance_array(self.u.atoms.positions, cog, box=box) ref = set(np.where((d > 2.4) & (d < 6.0))[0]) assert_(ref == set(result.indices))
def _check_spherical_zone(self, meth, periodic): sel = Parser.parse('sphzone 5.0 resid 1', self.u.atoms) sel = self.choosemeth(sel, meth, periodic) result = sel.apply(self.u.atoms) r1 = self.u.select_atoms('resid 1') cog = r1.center_of_geometry().reshape(1, 3) box = self.u.dimensions if periodic else None d = distance_array(self.u.atoms.positions, cog, box=box) ref = set(np.where(d < 5.0)[0]) assert_(ref == set(result.indices))
def _check_around(self, meth, periodic): sel = Parser.parse('around 5.0 resid 1', self.u.atoms) sel = self.choosemeth(sel, meth, periodic) result = sel.apply(self.u.atoms) r1 = self.u.select_atoms('resid 1') cog = r1.center_of_geometry().reshape(1, 3) box = self.u.dimensions if periodic else None d = distance_array(self.u.atoms.positions, r1.positions, box=box) ref = set(np.where(d < 5.0)[0]) # Around doesn't include atoms from the reference group ref.difference_update(set(r1.indices)) assert_(ref == set(result.indices))
def test_point(self, u, periodic): sel = Parser.parse('point 5.0 5.0 5.0 3.0', u.atoms) if periodic: sel.periodic = True else: sel.periodic = False result = sel.apply(u.atoms) box = u.dimensions if periodic else None d = distance_array(np.array([[5.0, 5.0, 5.0]], dtype=np.float32), u.atoms.positions, box=box) ref = set(np.where(d < 3.0)[1]) assert ref == set(result.indices)
def test_spherical_layer(self, u, periodic): sel = Parser.parse('sphlayer 2.4 6.0 resid 1', u.atoms) if periodic: sel.periodic = True else: sel.periodic = False result = sel.apply(u.atoms) r1 = u.select_atoms('resid 1') box = u.dimensions if periodic else None cog = r1.center_of_geometry().reshape(1, 3) d = distance_array(u.atoms.positions, cog, box=box) ref = set(np.where((d > 2.4) & (d < 6.0))[0]) assert ref == set(result.indices)
def test_spherical_zone(self, u, periodic): sel = Parser.parse('sphzone 5.0 resid 1', u.atoms) if periodic: sel.periodic = True else: sel.periodic = False result = sel.apply(u.atoms) r1 = u.select_atoms('resid 1') box = u.dimensions if periodic else None cog = r1.center_of_geometry().reshape(1, 3) d = distance_array(u.atoms.positions, cog, box=box) ref = set(np.where(d < 5.0)[0]) assert ref == set(result.indices)
def test_around(self, u, periodic): sel = Parser.parse('around 5.0 resid 1', u.atoms) if periodic: sel.periodic = True else: sel.periodic = False result = sel.apply(u.atoms) r1 = u.select_atoms('resid 1') cog = r1.center_of_geometry().reshape(1, 3) box = u.dimensions if periodic else None d = distance_array(u.atoms.positions, r1.positions, box=box) ref = set(np.where(d < 5.0)[0]) # Around doesn't include atoms from the reference group ref.difference_update(set(r1.indices)) assert ref == set(result.indices)
def _check_cyzone(self, meth, periodic): sel = Parser.parse('cyzone 5 4 -4 resid 2', self.u.atoms) sel.periodic = periodic result = sel.apply(self.u.atoms) other = self.u.select_atoms('resid 2') pos = other.center_of_geometry() vecs = self.u.atoms.positions - pos if periodic: box = self.u.dimensions[:3] vecs -= box * np.rint(vecs / box) mask = (vecs[:, 2] > -4) & (vecs[:, 2] < 4) radii = vecs[:, 0]**2 + vecs[:, 1]**2 mask &= radii < 5**2 ref = set(self.u.atoms[mask].indices) assert_(ref == set(result.indices))
def _check_cyzone(self, meth, periodic): sel = Parser.parse('cyzone 5 4 -4 resid 2', self.u.atoms) sel.periodic = periodic result = sel.apply(self.u.atoms) other = self.u.select_atoms('resid 2') pos = other.center_of_geometry() vecs = self.u.atoms.positions - pos if periodic: box = self.u.dimensions[:3] vecs -= box * np.rint(vecs / box) mask = (vecs[:,2] > -4) & (vecs[:,2] < 4) radii = vecs[:,0] ** 2 + vecs[:, 1] ** 2 mask &= radii < 5**2 ref = set(self.u.atoms[mask].indices) assert_(ref == set(result.indices))