Repository navigation
How is the cylinder defined in cyzone ? #5529
|
Hello there, |
Replies: 1 comment 1 reply
|
Your reading is almost right, with one important difference: the cylinder axis is always the box z-axis (lab frame). It is not tied to the orientation of your molecule. From vecs = group.positions - sel.center_of_geometry() # L477 (minimum-imaged if periodic)
mask = (vecs[:, 2] > self.zmin) & (vecs[:, 2] < self.zmax) # L516
radii = vecs[:, 0] ** 2 + vecs[:, 1] ** 2 # L522
mask = radii < self.exRadius**2 # L523So with COG = (x_g, y_g, z_g),
A quick check on a toy universe (MDAnalysis 2.11) confirms it: an atom 5.9 Å to the side and 3 Å above the COG (3D distance 6.6 Å) is selected by That means import numpy as np
from MDAnalysis.lib.distances import minimize_vectors
def flake_cylinder(flake, others, radius, zmax, zmin):
n = flake.principal_axes()[0] # largest moment of inertia -> plate normal
vecs = others.positions - flake.center_of_geometry()
if others.dimensions is not None:
vecs = minimize_vectors(vecs, others.dimensions)
h = vecs @ n # signed height along the normal
r = np.linalg.norm(vecs - np.outer(h, n), axis=1) # distance from the axis
keep = (h > zmin) & (h < zmax) & (r < radius)
return others[keep], h[keep]
flake = u.select_atoms("resname GO")
water = u.select_atoms("resname SOL and name OW")
for ts in u.trajectory:
inside, h = flake_cylinder(flake, water, 15, 8, -8)
n_above, n_below = (h > 0).sum(), (h < 0).sum()Two notes:
|
Your reading is almost right, with one important difference: the cylinder axis is always the box z-axis (lab frame). It is not tied to the orientation of your molecule.
From
CylindricalSelection._apply:So with COG = (x_g, y_g, z_g),
cyzone R zMax zMin selselects atoms withz_g + zMin < z < z_g + zMax(strict), and(x - x_g)² + (y - y_g)² < R². This is the distance in the xy-plane from the a…