Skip to content

gen_poscar.py

Julien Steffen edited this page Sep 2, 2025 · 6 revisions

This script builds a POSCAR file of a bulk or surface slab system, based on the most common lattice systems and surface facets.

An arbitrary number of elements can be added to the slab and their distribution on the lattice positions is done by chance, such that random alloys can be built.

To start the script, simply call it in the command line, together with the following keywords:

  • -lattice=[option] The chosen crystal lattice for the system. Currently available are: fcc (face-centered cubic), hcp (hexagonal close package) and sc (simple cubic).
  • -facet=[option] Which crystal facet shall be oriented in z-direction. If vacuum is introduced in z-direction, the slab corresponds to a surface of the respective facet. Currently available are: for fcc: 111, 100, 110: for hcp: 0001, 10-10; for sc: 100, 110. If the keyword is not given, the first facet in the list for the respective lattice will be chosen, e.g., 0001 for hcp.
  • -el_symbols=[list] The list of element symbols for the contained elements. This list determines in which order the elements will be given in the POSCAR file. Example: -el_symbols=Ga,Ag,In. An arbitrary number of elements can be given. There will however an error be thrown if any element has zero atoms (see below).
  • -el_freq=[list] The relative frequency of the elements in the system. Arbitrary numbers can be given, they are normalized internally. For example: -el_freq=0.5,0.25,0.25: 50% of the atoms will be element 1, and 25% each are element 2 and 3. The same result is reached with the command -el_freq=10,5,5. The number of values given must be identical to the number of elements in -el_symbols. Further, any element must be represented by at least one atom, else, an error is thrown. The placement of the elements is done by chance on the atom positions in the chosen lattice.
  • -lat_const=[value] The lattice constant of the chosen lattice, in Angstroms. Default value is 3.0.
  • -unit_x=[number] The number of lattice unit cells along the x axis (or, more general, the a axis). All given lattice facet unit cells contain only one atom, such that the total number of atoms in the system is equal to the product of the units in all three directions.
  • -unit_y=[number] The number of lattice unit cells along the y axis (or, more general, the b axis).
  • -unit_z=[number] The number of lattice unit cells along the z axis (or, more general, the c axis).

Further, a number of optional keywords with default values can be given to fine-tune the generation of the system:

  • -z_vac=[value] Size of the vacuum above the slab. Default: 20 Angstrom (i.e., a surface slab with enough separation to minimize interactions). If a bulk system shall be simulated, give 0 as value.
  • -x_vac=[value] Analog to -z_vac, but along the x-axis. Default: 0 Angstrom.
  • -x_vac=[value] Analog to -z_vac, but along the x-axis. Default: 0 Angstrom.
  • -z_shift=[value] Shift of the whole unit cell along the z axis. Default: 0 Angstrom. Give a value here if you want to have a slab in the center of the unit cell, with vacuum to both sides.
  • -x_shift=[value] Shift of the whole unit cell along the x axis. Default: 0 Angstrom. Give a value here and in the other shifts to generate an isolated particle.
  • -y_shift=[value] Shift of the whole unit cell along the y axis. Default: 0 Angstrom. Give a value here and in the other shifts to generate an isolated particle.

In the following, some example cases for typical setups are given:

Case 1: bulk: If we want to generate a simple cubic bulk cell, for example as starting point for melting an arbitrary alloy, you can do the following:

gen_poscar.py -lattice=sc -facet=100 -el_symbols=Ga,In,Sn -el_freq=4,3,1 -lat_const=2.5 -unit_x=8 -unit_y=8 -unit_z=8 -z_vac=0.0

An alloy containing 512 atoms (256 Ga, 192 In, 64 Sn) on a regular 8x8x8 grid is built. No vacuum is introduced by setting -z_vac to zero.

Case 2: surface slab: A hcp 0001 surface slab of Ru and a small amount of Ag (2 at%) can be built with the following command:

gen_poscar.py -lattice=hcp -facet=0001 -el_symbols=Ru,Ag -el_freq=49,1 -lat_const=3.2 -unit_x=5 -unit_y=5 -unit_z=6 -z_vac=12.0

The surface slab is built, with 147 Ru and 3 Ag atoms, arbitrarily distributed.

Case 3: isolated cluster: To generate an isolated fcc metal cluster containing Sn, Ag and Pt, use the following command:

gen_poscar.py -lattice=fcc -facet=100 -el_symbols=Sn,Ag,Pt -el_freq=2,2,1 -lat_const=2.8 -unit_x=6 -unit_y=8 -unit_z=7 -x_vac=15.0 -y_vac=15.0 -z_vac=15.0 -x_shift=7.5 -y_shift=7.5 -z_shift=7.5

A parallelepiped with different axis lengths located in the center of the unit cell is built, containing the three chosen elements distributed by chance and surrounded by 15 Angstroms of vacuum. The surfaces are the low miller index ones (100, 010, 001), with 100 pointing upwards along the z-axis.

Clone this wiki locally