[ase-users] swap atoms
Ask Hjorth Larsen
asklarsen at gmail.com
Fri Jul 28 15:15:41 CEST 2017
Hi
2017-07-28 5:44 GMT+02:00 Tristan Maxson via ase-users
<ase-users at listserv.fysik.dtu.dk>:
> I think a function like this is reasonable, but the following can be done
> just as easily. I can put in a pull request for the next version of ASE with
> something like this, we can work out details on naming on the request.
>
> Try something like this
>
> atoms[i_a].position, atoms.position[i_b] = atoms.position[i_b],
> atoms.position[i_a]
>
> This could get pretty ugly looking in code very quickly though and a helper
> function makes sense. Thank you for the suggestion.
Another way is:
atoms.positions[[i, j]] = atoms.positions[[j, i]]
I think this simple enough that a method is not needed. It is a bit
unclear what a method called swap() exactly does (does it interchange
the species, or the position, or reorder the atoms object itself,
...), so it is likely more clear to do it directly on the array
anyway.
Best regards
Ask
>
> Tristan Maxson
>
>
> On Thu, Jul 27, 2017 at 10:42 PM, Oscar Xavier Guerrero via ase-users
> <ase-users at listserv.fysik.dtu.dk> wrote:
>>
>> Hello,
>>
>> I am interested in swapping the positions of two atoms.
>>
>> This is what I'm doing right now:
>>
>> atoms = init_atoms.copy()
>> atoms[i_a].position = init_atoms[i_b].get('position')
>> atoms[i_b].position = init_atoms[i_a].get('position')
>>
>> Here i_a and i_b are the indices of the two atoms I want to swap. Should
>> there be a function in the atoms object that mutates it or returns a copy?
>> Something like:
>>
>> atoms.exchange(i_a, i_b)
>> atoms.swap(i_a, i_b)
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> 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