wulfric.crystal.ensure_unique_names#
- wulfric.crystal.ensure_unique_names(atoms, strategy: str = 'all') None[source]#
Ensures that atoms have unique
"names".If atom names are already unique, then this function does nothing.
Added in version 0.5.1.
- Parameters:
- atomsdict
Dictionary with atoms. Must have a
"names"keyword with the value oflistof Nstr.- 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 grooup. (See examples)
Case-insensitive.
- Raises:
- ValueError
If
strategyis not supported.
Examples
>>> import wulfric as wulf >>> atoms = {"names" : ["Cr1", "Cr2", "Br", "Br", "S", "S"]} >>> # Default strategy is "all" >>> wulf.crystal.ensure_unique_names(atoms) >>> atoms {'names': ['Cr11', 'Cr22', 'Br3', 'Br4', 'S5', 'S6']} >>> atoms = {"names" : ["Cr1", "Cr2", "Br", "Br", "S", "S"]} >>> wulf.crystal.ensure_unique_names(atoms, strategy="repeated-only") >>> atoms {'names': ['Cr1', 'Cr2', 'Br1', 'Br2', 'S1', 'S2']} >>> # Nothing happens if atom names are already unique >>> wulf.crystal.ensure_unique_names(atoms) >>> atoms {'names': ['Cr1', 'Cr2', 'Br1', 'Br2', 'S1', 'S2']} >>> wulf.crystal.ensure_unique_names(atoms, strategy="repeated-only") >>> atoms {'names': ['Cr1', 'Cr2', 'Br1', 'Br2', 'S1', 'S2']}