[ase-users] Sort Atoms in specific Order
Eric Hermes
ehermes at chem.wisc.edu
Fri Apr 7 15:48:41 CEST 2017
As far as I am aware there is no baked-in method in ASE to do what you
want, but fortunately it is still possible with a little bit of
scripting. Here is how I would go about doing it:
Say you have a geometry with the order C Cu H O, and you want to
reorder it to be C H Cu O, as you have said. You can reorder the object
by looping over atoms in your Atoms object and pulling out the indices
of the desired atomic type one by one such as in the following example
def get_indices(atoms, symbol):
indices = []
for atom in atoms:
if atom.symbol == symbol
indices.append(atom.index)
return indices
# Alternatively, you could use a list comprehension to make this
# shorter
#return [atom.index for atom in atoms if atom.symbol == symbol]
new_indices = []
for symbol in ['C', 'H', 'Cu', 'O']:
new_indices.append(get_indices(slab, symbol))
slab = slab[new_indices]
Eric
On Fri, 2017-04-07 at 14:11 +0200, fabian via ase-users wrote:
> Hi Mikkel ,
>
> Thanks for your answer! This seems to work if the number of atoms is
> not
> to large as the permutation seems to address individual atoms by
> their
> position within the slab?
>
> For a slab with a large amount of atoms this doesn´t seem to work as
> well ( if i am not missing the point). This is why i want to change
> the
> order of atoms
>
> (from C Cu H O to C H Cu O in my case) by addressing the atoms
> with
> their name tag.
>
> Do you have an idea how to achieve this?
>
>
> All the best
>
>
> fabian
>
>
> Am 07.04.2017 um 13:12 schrieb Mikkel Strange:
> > Hi Fabian,
> >
> > perhaps you could use a list of indices to reorder the atoms the
> > way you like them.
> > Here is a simple example:
> >
> > from ase import Atoms
> > slab = Atoms(symbols='HHeLi')
> > perm = [2, 0, 1]
> > slab = slab[perm]
> >
> > which produces
> > Atoms(symbols='LiHHe')
> >
> > best regards,
> > Mikkel
> >
> >
> > ________________________________________
> > From: ase-users-bounces at listserv.fysik.dtu.dk [ase-users-bounces at li
> > stserv.fysik.dtu.dk] on behalf of fabian via ase-users [ase-users at l
> > istserv.fysik.dtu.dk]
> > Sent: Friday, April 07, 2017 12:05 PM
> > To: ase-users
> > Subject: [ase-users] Sort Atoms in specific Order
> >
> > Dear all ,
> >
> > I want to sort the order of the atoms in my Output files
> >
> > in a specific order.
> >
> > currently i use:
> >
> > slab=sort(slab, tags=None)
> >
> > Which sets them in alphabetical order. I want to determine the
> > order myself
> >
> > All the best
> >
> >
> > fabian
> >
> > _______________________________________________
> > ase-users mailing list
> > ase-users at listserv.fysik.dtu.dk
> > https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>
> _______________________________________________
> ase-users mailing list
> ase-users at listserv.fysik.dtu.dk
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
More information about the ase-users
mailing list