@@ -183,6 +183,89 @@ def _test_atomselect(pdbid, sel, _pdbmols):
183183 pickle .dump (results , f )
184184
185185
186+ def _test_empty_molecule ():
187+ mol = Molecule ()
188+ selections = [
189+ "all" ,
190+ "protein" ,
191+ "nucleic" ,
192+ "water" ,
193+ "lipid" ,
194+ "ion" ,
195+ "backbone" ,
196+ "sidechain" ,
197+ "hydrogen" ,
198+ "noh" ,
199+ "name CA" ,
200+ "resname ALA" ,
201+ "resid 1" ,
202+ "chain A" ,
203+ "index 0" ,
204+ "serial 1" ,
205+ "element C" ,
206+ "mass < 5" ,
207+ "x < 6" ,
208+ "beta >= 0" ,
209+ "not protein" ,
210+ ]
211+ for sel in selections :
212+ res = mol .atomselect (sel )
213+ assert res .shape == (0 ,), f"Expected empty result for '{ sel } ', got shape { res .shape } "
214+ assert res .dtype == bool , f"Expected bool dtype for '{ sel } ', got { res .dtype } "
215+
216+
217+ def _test_single_atom_molecule ():
218+ mol = Molecule ()
219+ mol .empty (1 )
220+ mol .record [:] = "ATOM"
221+ mol .name [:] = "CA"
222+ mol .resname [:] = "ALA"
223+ mol .resid [:] = 1
224+ mol .chain [:] = "A"
225+ mol .element [:] = "C"
226+ mol .coords = np .zeros ((1 , 3 , 1 ), dtype = np .float32 )
227+
228+ expected_true = [
229+ "all" ,
230+ "name CA" ,
231+ "resname ALA" ,
232+ "resid 1" ,
233+ "chain A" ,
234+ "element C" ,
235+ "index 0" ,
236+ "serial 1" ,
237+ "noh" ,
238+ "not nucleic" ,
239+ "not water" ,
240+ "x < 6" ,
241+ "beta >= 0" ,
242+ ]
243+ for sel in expected_true :
244+ res = mol .atomselect (sel )
245+ assert res .shape == (1 ,), f"Expected shape (1,) for '{ sel } ', got { res .shape } "
246+ assert res .dtype == bool
247+ assert res [0 ], f"Expected True for '{ sel } '"
248+
249+ expected_false = [
250+ "nucleic" ,
251+ "water" ,
252+ "lipid" ,
253+ "ion" ,
254+ "hydrogen" ,
255+ "name CB" ,
256+ "resname GLY" ,
257+ "resid 2" ,
258+ "chain B" ,
259+ "element N" ,
260+ "index 1" ,
261+ ]
262+ for sel in expected_false :
263+ res = mol .atomselect (sel )
264+ assert res .shape == (1 ,), f"Expected shape (1,) for '{ sel } ', got { res .shape } "
265+ assert res .dtype == bool
266+ assert not res [0 ], f"Expected False for '{ sel } '"
267+
268+
186269def _test_numprop_list_equality ():
187270 pdb = os .path .join (curr_dir , "test_atomselect" , "test.pdb" )
188271 mol = Molecule (pdb )
0 commit comments