Skip to content

Clearer Failure Error or Returning Empty AtomGroup with Selections e.g. cyzone #3026

@yuxuanzhuang

Description

@yuxuanzhuang

Expected behavior

When using some selection syntax e.g. sphzone, cyzone for an empty selection, the error should be "You are selecting within an empty AtomGroup" or just return an empty group (like with around)

Actual behavior

When using selection syntax e.g. sphzone, cyzone for a empty selection, the error is not clear enough.

Code to reproduce the behavior

>>> import MDAnalysis as mda
>>> from MDAnalysis.tests.datafiles import PSF, DCD

>>> u = mda.Universe(PSF, DCD)
>>> ag = u.select_atoms('sphzone 10 resname blabla')

--> 333         ref = sel.center_of_geometry().reshape(1, 3).astype(np.float32)
    334         pairs = distances.capped_distance(ref, group.positions, self.cutoff,
    335                                           box=box,

ValueError: cannot reshape array of size 0 into shape (1,3)

>>> ag = u.select_atoms('cyzone 10 6 -6 resname blabla')

--> 349         vecs = group.positions - sel.center_of_geometry()
    350 
    351         if self.periodic and not np.any(group.dimensions[:3] == 0):

ValueError: operands could not be broadcast together with shapes (3341,3) (0,3)

while for around...

>>> ag = u.select_atoms('around 10 resname blabla')
>>> ag
<AtomGroup with 0 atoms>

Possible solution

I am in favor of just seeing an empty AtomGroup in these cases.

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)") 2.0.0-dev
  • Which version of Python (python -V)? 3.8
  • Which operating system? Ubuntu 18

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions