@@ -143,7 +143,7 @@ def __post_init__(self) -> None:
143143 assert type (self .atoms ) is np .ndarray
144144
145145 # pre-compute heavy atom mask once
146- if self .heavy_atoms_only :
146+ if self .heavy_atoms_only and np . count_nonzero ( self . atoms != "H" ) > 0 :
147147 self ._heavy_mask : Array1D_bool = self .atoms != "H"
148148 else :
149149 self ._heavy_mask = np .ones (self .atoms .shape [0 ], dtype = np .bool_ )
@@ -187,6 +187,15 @@ def __post_init__(self) -> None:
187187 for c , coord in enumerate (self .structures )
188188 }
189189
190+ # check the first structure to assess if any
191+ # moment is zero and we should therefore not
192+ # bother using it to compare structures
193+ self .check_I_on_axis : tuple [bool , bool , bool ] = (
194+ self .moi_vecs [0 ][0 ] > 1e-6 ,
195+ self .moi_vecs [0 ][1 ] > 1e-6 ,
196+ self .moi_vecs [0 ][2 ] > 1e-6 ,
197+ )
198+
190199 def evaluate_sim (self , i1 : int , i2 : int ) -> bool :
191200 """Return whether the structures are similar."""
192201 im_1 = self .moi_vecs [i1 ]
@@ -195,8 +204,8 @@ def evaluate_sim(self, i1: int, i2: int) -> bool:
195204 # compare the three MOIs via a Python loop:
196205 # apparently much faster than numpy array operations
197206 # for such a small array!
198- for j in range ( 3 ):
199- if np .abs (im_1 [j ] - im_2 [j ]) / im_1 [j ] >= self .max_dev :
207+ for j , check_axis in enumerate ( self . check_I_on_axis ):
208+ if check_axis and np .abs (im_1 [j ] - im_2 [j ]) / im_1 [j ] >= self .max_dev :
200209 return False
201210 return True
202211
@@ -503,8 +512,12 @@ def _batch_rmsd_prune(
503512 start_t = perf_counter ()
504513
505514 N = len (structures )
515+
516+ # check how many heavy atoms: if none, use all
517+ M = int (np .count_nonzero (atoms != "H" ))
518+
506519 heavy_mask : Array1D_bool = (
507- atoms != "H" if heavy_atoms_only else np .ones (structures .shape [1 ], dtype = bool )
520+ atoms != "H" if ( heavy_atoms_only and M > 0 ) else np .ones (structures .shape [1 ], dtype = bool )
508521 )
509522 M = int (heavy_mask .sum ())
510523
0 commit comments