wulfric.crystal.get_unique_names#
- wulfric.crystal.get_unique_names(atoms, strategy: str = 'all') list[source]#
Ensures that atoms have unique
"names".If atom names are already unique, then returns
atoms["names"].- Parameters:
- atomsdict
Dictionary with N atoms. Expected keys:
"names" : (N, ) list of str
- strategystr, default "all"
Strategy for the modification of atom names. Supported strategies are
"all"
Add an index to the end of every atom, starting from 1.
"repeated-only"
Add an index only to the repeated names, index starts with 1, independently for each repeated group. (See examples)
Case-insensitive.
- Returns:
- unique_nameslist of str
Unique names of atoms.
- Raises:
- ValueError
If
strategyis not supported.
Examples
>>> import wulfric >>> atoms = {"names": ["Cr1", "Cr2", "Br", "Br", "S", "S"]} >>> # Default strategy is "all" >>> wulfric.crystal.get_unique_names(atoms) ['Cr11', 'Cr22', 'Br3', 'Br4', 'S5', 'S6'] >>> atoms = {"names": ["Cr1", "Cr2", "Br", "Br", "S", "S"]} >>> wulfric.crystal.get_unique_names(atoms, strategy="repeated-only") ['Cr1', 'Cr2', 'Br1', 'Br2', 'S1', 'S2'] >>> # Nothing happens if atom names are already unique >>> wulfric.crystal.get_unique_names(atoms) ['Cr1', 'Cr2', 'Br1', 'Br2', 'S1', 'S2'] >>> wulfric.crystal.get_unique_names(atoms, strategy="repeated-only") ['Cr1', 'Cr2', 'Br1', 'Br2', 'S1', 'S2']