modify_poscar.py - Trebonius91/utils4VASP GitHub Wiki

This python script performs several modifications of POSCAR files for a convenient modification of periodic structures in general. It can multiply unit cells, shift some or all atom of a unit cell by a certain factor, convert between fractional and cartesian coordinates, freeze or unfreeze certain atoms and insert another structure into a POSCAR file, by removing all atoms of it in the area where collisions could occur.

The script is managed entirely via command line arguments. To apply it, go into a folder where the POSCAR file is located and execute the script. If no arguments are given, all available commands are written. Else, the desired operation is done and a modified file named POSCAR_mod is written. The modified (or unmodified) structure can be also stored as xyz file, which is then called poscar_mod.xyz.

List of available commands:

  • -shift=a,b,c Shift all or some chosen atoms in the unit cell by a vector in direct coordinates, given by the values after the command. If only some atoms shall be moved, the commands select_el or select_ind can be used to select the atoms that shall be moved (for example only some adsorbate molecules, but not the underlying surface and other molecules). For example: -shift=0.1,0.5,0.0, would shift the atoms mostly along the b axis, but not along the c axis.
  • **-multiply=a,b,c ** Multiplies the unit cell, such that a supercell with many identical unit cells is obtained. For example: multiply=3,3,1, would be suitable if a surface slab shall be multiplied threefold in both directions.
  • -frac2cart Translate a POSCAR given in fractional/direct coordinates to cartesian coordinates.
  • -cart2frac Translate a POSCAR given in cartesian coordinates to fractional/direct coordinates.
  • -map2unit If image flags are present in a POSCAR file, for example after doing a MD simulation where some atoms moved several unit cells, they are removed and all atoms are put back into the unit cell.
  • -freeze=list Set the movement flags of all atoms belonging to the given list of elements to F F F, i.e., freezes them for a selective dynamics. For example -freeze=Si,O would freeze all atoms of a silica surface, whereas the Pt cluster located on it is still movable.
  • -select_el=list If only some atoms shall be moved with the shift command, select the elements whose atoms shall be moved. Example -select_el=C,H** selects only C and H atom, maybe of an anthracene molecule adsorbed on a metal surface.
  • -select_ind=list Select all indices of atoms that shall be moved with the shift command, if for example only some atoms of a certain element shall be moved. Both individual indices and longer lists of connected indices can be given simultaneously. For example: -select_ind=20,51-76,82,100-110.
  • -insert_struc=a,b,c Inserts a structure given by POSCAR_insert into the POSCAR structure. The parameters a, b and c (in direct coordinates) give the desired position of the center of mass of the inserted structure with respect to the coordinates of the overall POSCAR file. It is important that the inserted structure is smaller than the structure in POSCAR and that no atom of the inserted structure leaves the central unit cell of the surrounding POSCAR, since else the removal of atoms near the inserted structure does not work. If the structure is set reasonably, all atoms in the POSCAR structure located too near to the inserted atoms are removed to avoid collisions. The distance below which the removal happens can be set with the -remove_dist keyword.
  • -bottom=[value] Set all atoms with a z-coordinate below the given value to F F F, i.e., freeze them. The value can be either given in direct or in cartesian coordinates, depending of the format of the given POSCAR file (direct or cartesian). Example: -bottom=3.5 with a POSCAR given in cartesian coordinates: all atoms below z=3.5 Ang. are frozen (for example in a surface slab).
  • -remove_dist=[value] For the -insert_struc command: All atoms of the POSCAR with a distance equal or nearer the given value to any of the atoms of the inserted structure in POSCAR_insert are removed to avoid collisions. Independent of the given coordinate format, the value must always be given in Angstroms. Example: -remove_dist=3.5: All atoms with distances below 3.5 Ang. are removed. The default is 2.5 Angstroms, which should be reasonable in most cases.
  • -phasetrans=[axis] A unitcell for a phase transition sampling (for example a crystal structure vs a liquid with the same composition) will be build. This command must be given in combination with -multiply. [axis] must be set to a, b or c, depending the direction along which the phases shall border each other. Further, the -multiply must have an equal number along the axis given by this keyword. Then, the atoms in the lower part of the cell will be kept fix (F F F) and those in the upper part will be free to move (T T T). Then, the phase can be melted at a high temperature only at the upper part and the phase transition can be studied with all atoms free to move at a lower temperature in a separate calculation. Example: -phasetrans=c together with -multiply=2,3,4. The lower half of the multipled cell along the c axis will be kept fix (two unit cells), the upper half will be free to move.
  • -writexyz Write the coordinates of the updated structure (after executing all commands above) to a xyz file named poscar-mod.xyz.