[ase-users] Resort atoms object by atom number
Eric Hermes
ehermes at chem.wisc.edu
Fri Dec 8 20:15:01 CET 2017
On Fri, 2017-12-08 at 19:47 +0100, fabian via ase-users wrote:
> Dear all,
> I read a POSCAR file into an atoms object via
> atoms = read("POSCAR")
> now i want to resort the atoms object such that the atom with the
> Number n_atom is moved from its postion to the index 0
> (1 if not counted the pythonic way), such that it is later writen as
> the first entry into the atoms object.
> later i want to write the object via:
> write('POSCAR', atoms, vasp5=True, sort=False,
> direct=True,long_format=True, format='vasp')
> and have the entry corresponding to n_atom as the first Atom in the
> POSCAR file. I found a dirty workaround with temp files but
> this means i have to convert each initial structure to the right
> format . Else i create wrong files.
> Is this possible within ASE?
> On a side not if i pop an atom via:
> atoms.pop( n_atom)
>
> is n_atom defined the pythonic way and starting at 0?
To start by answering your last question: yes, everything in ASE is 0-
indexed. Note that this is not only the Pythonic way, it is a common
standard used by most languages with some notable exceptions (Fortran,
Julia, and R probably being the most relevant).
In fact, you should be able to use Atoms.pop() to do exactly what you
want. Try the following:
atoms = atoms.pop(n_atom) + atoms
One other thing is that when ASE sorts VASP POSCAR files, the first
atom will never change place, so sort=False is not completely necessary
(you can still use it if you want to though).
Eric
>
> Al the best
> fabian
> _______________________________________________
> 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