The Swiss-army knife of atomic simulations
This tutorial explains how to combine several selection criteria.
▶ For more information, refer to the corresponding documentation page.
For the sake of the exercise, let us create a supercell of fcc aluminium:
atomsk --create fcc 4.046 Al -duplicate 40 30 1 Al.cfg
The previous tutorials have provided several examples of the option "-select". For instance, the following command selects atoms inside a sphere, then invert the selection (so the atoms outside of the sphere are selected), and then removes atoms:
atomsk Al.cfg -select in sphere 0.35*box 0.5*box 0.5*box 50 \
-select invert -rmatom select groupA.cfg
Let us call this group of atoms "group A". The result can be visualized:
This sphere is placed slightly on the left, because we used "0.35*box" along the X direction in the option "-select". Similarly, we can place it on the right side by using "0.65*box" instead:
atomsk Al.cfg -select in sphere 0.65*box 0.5*box 0.5*box 50 \
-select invert -rmatom select groupB.cfg
Let us call this group of atoms "group B":
Now, what happens if we use the option "-select" twice? Let us try it:
atomsk Al.cfg -select in sphere 0.35*box 0.5*box 0.5*box 50 \
-select in sphere 0.65*box 0.5*box 0.5*box 50 \
-select invert -rmatom select test.cfg
The result is just the same as before, i.e. only atoms of group B remain. This is because, if you call the option "-select" while a selection is already defined, then Atomsk erases the previous selection, and replaces it by the new one. In the previous command, the first call to "-select" is completely overridden by the second call, and only the second sphere is selected.
In order to combine several selections, one may use an additional keyword, to be placed right after the keyword "-select".
First, let us assume that we want to select all atoms that belong to group A or group B. In other words, we want to add atoms of group B, to the atoms of group A. To achieve that, select atoms of group A "normally", i.e. just like the first command above. Then, call the option a second time, using "-select add" to add atoms that belong to the second sphere (group B):
atomsk Al.cfg -select in sphere 0.35*box 0.5*box 0.5*box 50 \
-select add in sphere 0.65*box 0.5*box 0.5*box 50 \
-select invert -rmatom select add.cfg
This command selects atoms that are inside the first sphere (group A), and then adds to the selection the atoms belonging to the second sphere (group B), using the parameters provided. Then, like before, the selection is inverted, and atoms are removed, so that only atoms that belong to groups A or B remain:
Note that the atoms that belong to group A, and also to group B, remain selected. Also, keep in mind that this operation just performs a selection: the option "-select" in itself does not add or remove atoms, it only changes their status to "selected" or "not selected". In the command above, the atoms are deleted by the option "-rmatom".
Now, assume that after selecting atoms belonging to group A, we wish to remove atoms that belong to group B. This can be achieved by using "-select rm":
atomsk Al.cfg -select in sphere 0.35*box 0.5*box 0.5*box 50 \
-select rm in sphere 0.65*box 0.5*box 0.5*box 50 \
-select invert -rmatom select rm.cfg
This command will select atoms belonging to the first sphere (group A), and then remove from this selection the atoms that belong to the second sphere (group B):
Now, assume that we want to keep only atoms that belong to both groups A and B. This time, use the keyword "intersect":
atomsk Al.cfg -select in sphere 0.35*box 0.5*box 0.5*box 50 \
-select intersect in sphere 0.65*box 0.5*box 0.5*box 50 \
-select invert -rmatom select intersect.cfg
This command will select atoms belonging to the first sphere (group A), and then keep only atoms that also belong to the second sphere (group B):
Finally, it is also possible to select atoms that belong to either group A or group B, but not both (this is equivalent to the exclusive OR operator, or XOR):
atomsk Al.cfg -select in sphere 0.35*box 0.5*box 0.5*box 50 \
-select xor in sphere 0.65*box 0.5*box 0.5*box 50 \
-select invert -rmatom select xor.cfg
This command will select atoms belonging to the first sphere (group A), add the atoms that belong to the second sphere (group B), and remove atoms that belong to both spheres:
The examples above are simplistic, to explain the purpose of each keyword. Yet it is possible to call the option "-select" several times with those keywords, to add or remove atoms from the selection, and construct complex shapes. Each time the option "-select" is called with such a keyword, it will keep the previous selection, and modify it according to the new provided criteria.
For instance, let us assume that we want a surface of aluminium covered with small spheres. This can be achieved by selecting atoms below a given plane, and then adding some spheres to the selection:
atomsk Al.cfg -dup 1 1 10 \
-select below 0.5*box Y \
-select add in sphere 0.15*box 0.5*box 0.25*box 20 \
-select add in sphere 0.45*box 0.5*box 0.75*box 20 \
-select add in sphere 0.75*box 0.5*box 0.15*box 20 \
-select invert -rmatom select test.cfg
Again, bear in mind that the sequence of options "-select" does not add or remove atoms from the system. They only select or un-select atoms according to the given criteria -therefore, the same atom can be selected, then de-selected, and then selected again depending on the criteria that are used. To delete atoms, one must call an option that actually removes atoms, such as the option "-remove-atoms". You may play with the command above, to place cubes or carve spheres on the surface for instance.
As another example, assume that we want to build a nanopillar at the bottom of a spherical hole. To do that, select atoms below a given plane (that will be the substrate); then remove from this selection the atoms that belong to a sphere placed above the substrate; then, add atoms that belong to a cylinder to the selection (that will be the nanopillar). In addition, we can remove from the selection the atoms that are too close to the top of the box along Y. At this point, the substrate and the nanopillar are selected. Invert the selection, and then remove selected atoms: only the substrate and the nanopillar will remain.
atomsk Al.cfg -dup 2 1 20 \
-select below 0.5*box Y \
-select rm in sphere 0.5*box box 0.5*box 100 \
-select add in cylinder Y 0.5*box 0.5*box 30 \
-select rm above 0.9*box Y \
-select invert -rmatom select test.cfg
Again, you may play with this example to obtain various curvatures for the spherical hole, or different radius for the nanopillar.
In summary, the option "-select" combined with the keywords "add", "rm", "intersect", and "xor", is a powerful tool to manipulate a selection before actually doing anything with it. All examples above removed the selected atoms, but instead, you may also substitute atoms, displace them, and so on.