Get site IDs of specific species

I want to get site IDs of one species, from a structure created from a VASP POSCAR file.
While this works,
structure['C'] = ['B']
this for example doesn’t
sites = structure['C']
and I don’t understand why.
This may be an easy question but I have just started using pymatgen.
Thanks for any input.

If I understood correctly, you want the indices of all sites that are Carbon, right?
This should work:

indices = [i for i, specie in enumerate(structure.species) if specie.symbol == 'C']


this worked perfectly, thank you very much.

1 Like