This tutorial explains how to remove atoms based on various criteria.
▶ For more information, refer to the corresponding documentation page.
For the sake of the exercise, let us create a supercell of rocksalt NaCl:
atomsk --create rocksalt 5.64 Na Cl -duplicate 10 10 10 NaCl_supercell.xsf
The option "-remove-atoms", as its name indicates, allows to remove atoms from the system. It can be used in two ways. First, it can be used to remove all atoms belonging to a given species. For instance, if you wish to remove all Cl ions from the system:
atomsk NaCl_supercell.xsf -remove-atoms Cl final.cfg
Second, it can be used to remove a single atom, corresponding to the given index. This can be used to introduce a vacancy in the system. For instance, to remove the atom number 417 from the system:
atomsk NaCl_supercell.xsf -remove-atoms 417 final.cfg
When visualizing the coordination within Atomeye (press K), the neighbors of the vacancy have a different color:
Note that is the given number is out of bounds (e.g. if there are only 400 atoms in the system and you ask to remove number 417), then a warning will be displayed and no atom will be removed.
An important thing to note: as always, Atomsk applies options sequencially, in the order in which they appear. So, if you wish to remove two atoms, the ordering of the options is important. Always remove the atom with the highest index first. For instance if you wish to remove atoms numbers 210 and 417, the following will achieve what you want:
atomsk NaCl_supercell.xsf -remove-atoms 417 -remove-atoms 210 final.cfg
However the following will not remove the correct atom:
atomsk NaCl_supercell.xsf -remove-atoms 210 -remove-atoms 417 final.cfg
Why is that? Atomsk will start by removing the atom number 210. As a result, all atoms of higher index will have an index that is different from the original system: atom number 211 becomes number 210, 212 becomes 211, and so on. So, after that when Atomsk removes the atom number 417, it actually removes the atom that formerly had the index number 418, which is not what you wanted.
Of course, when the purpose is to create several vacancies, the usage of the option "-remove-atoms" can become very tedious. If you wish to remove 20 or 300 atoms in the system, you may find it impractical to use the option "-remove-atoms" that many times. Fortunately there are alternatives.
The option "-select" allows to select atoms according to various criteria in a flexible way. Let us review the various possibilities.
First, you may use the option "-select" to select all atoms that belong to the same species. For instance, to select all Cl atoms:
atomsk NaCl_supercell.xsf -select Cl final.cfg
Now, understand that this "selection" is internal to Atomsk, and does not actually do anything to the system. In this command, Cl atoms were selected, but nothing was done to them -they were not removed nor anything. So, when comes the time to write the final file "final.cfg", Atomsk writes all atom positions in the file, no matter if they are selected or not.
The selection however, modifies the behavior of options within Atomsk. Instead of applying to all atoms, options will apply only to the selected atoms. For instance, if you use "-select Cl" and then use the option "-remove-atoms Cl", then only the selected Cl atoms are deleted:
atomsk NaCl_supercell.xsf -select Cl -remove-atoms Cl final.cfg
The latter option can also be used to remove the selected atoms, by using "select" instead of an atom symbol:
atomsk NaCl_supercell.xsf -select Cl -remove-atoms select final.cfg
Of course, so far this has little interest since it has the same effect as just using "-remove-atoms Cl". However it becomes useful when the selection is a bit more complicated.
The option "-select" can be used to select atoms according to their index. Contrary to the option "-remove-atoms" that accepts only one index, the option "-select" can be used to select several atoms, by giving their index separated by a comma (and with no white space):
atomsk NaCl_supercell.xsf -select 210,417,618 -remove-atoms select final.cfg
This can be practical when one wants to select several atoms at a time. Again, understand that the option "-select" only selects atoms, and then the option "-remove-atoms select" removes all atoms that are selected, no matter if they are Na or Cl atoms.
It is also possible to select a range of indices by using a semicolon:
atomsk NaCl_supercell.xsf -select 210,417,600:670,18,90 -remove-atoms select final.cfg
In this case the atoms number 210, 417, 600 to 670, 18, and 90, are selected; then they are removed from the system. Note that the numbers may be in any order, since the selection applies to the current system and no atom is removed by the option "-select", so there is no risk of shifted indices.
It is possible to select atoms randomly in the system. For that, specify the number of atoms and their species. For instance, to remove 30 atoms of Na at random, use the following:
atomsk NaCl_supercell.xsf -select random 30 Na -remove-atoms select final.cfg
It is also possible to remove a given portion of atoms, using the symbol "%". For instance, to remove 1.5% of Na atoms from the system:
atomsk NaCl_supercell.xsf -select random 1.5% Na -remove-atoms select final.cfg
If you want to remove both Na and Cl atoms randomly, then replace the atom symbol by the keyword "any":
atomsk NaCl_supercell.xsf -select random 30 any -remove-atoms select final.cfg
The option "-select" has other capabilities, like selcting atoms that are in a box, a sphere, or a cylinder. They are discussed in the following tutorials.