7
$\begingroup$

I am trying to sort a set of Cu atoms in a fcc (non primitive) crystal structure according to their Z cordinate. I am using ase.build.sort to do this with the help of doccumentation. The doccumentation says that for ase.build.sort(atoms, tags=None), it will return a new Atoms object with sorted atomic order. The default is to order according to chemical symbols, but if tags is not None, it will be used instead.

But there is no clue given how to sort in some different manner (not according to chemical symbols).

Here is my code:

import os
import numpy
import ase
import ase.io
import ase.build
import ase.visualize

from ase.build import bulk
from ase.build.tools import sort

Cu=ase.build.bulk('Cu','fcc',a=3.6, cubic=True)
surface=ase.build.surface(Cu,(1,1,1),4,vacuum=15)

from ase.build import bulk
from ase.build.tools import sort

surface_sorted = sort(surface,tag=)

What should I put in the tag so that I can get it sorted according to z coordinates?

$\endgroup$
7
$\begingroup$

The following code should create a Cu surface and sort it by z index. We do this by providing tags for the positions of the atoms. [:, 2] allows us to select the z position of all atoms.

from ase.build import bulk, surface
from ase.build.tools import sort

Cu = ase.build.bulk('Cu', 'fcc', a=3.6, cubic=True)
surface = ase.build.surface(Cu, (1,1,1), 4, vacuum=15)

surface_sorted = sort(surface, tags=surface.positions[:, 2])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.