Filters atoms based on the provided filtering type and element subset.
Parameters:
atoms (ase.Atoms): The atoms object to filter.
element_subset (list): The list of elements to consider during filtering.
filtering_type (FilteringType): The type of filtering to apply.
Can be one of the following `FilteringType` enum members:
- `FilteringType.NONE`: No filtering is applied.
- `FilteringType.COMBINATIONS`: Return true if `atoms` is composed of combinations of elements in the subset, false otherwise. I.e. does not require all of the specified elements to be present.
- `FilteringType.EXCLUSIVE`: Return true if `atoms` contains *only* elements in the subset, false otherwise.
- `FilteringType.INCLUSIVE`: Return true if `atoms` contains all elements in the subset, false otherwise. I.e. allows additional elements.
Returns:
bool: True if the atoms pass the filter, False otherwise.
"""
iffiltering_type==FilteringType.NONE:
returnTrue
iffiltering_type==FilteringType.COMBINATIONS:
atom_symbols=np.unique(atoms.symbols)
returnall(
xinelement_subsetforxinatom_symbols
)# atoms must *only* contain elements in the subset
iffiltering_type==FilteringType.EXCLUSIVE:
atom_symbols=set(list(atoms.symbols))
returnatom_symbols==set(element_subset)
iffiltering_type==FilteringType.INCLUSIVE:
atom_symbols=np.unique(atoms.symbols)
returnall(
xinatom_symbolsforxinelement_subset
)# atoms must *at least* contain elements in the subset
raiseValueError(
f"Filtering type {filtering_type} not recognised. Must be one of {list(FilteringType)}."