Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
ASE scripts
ASE provides very convenient tool to manipulate the structures and convert them to different file formats.
Below is a python script to read the structure from gen format (used in DFTB+) and then make a 333 supercell in gen and vasp format.
fromase.ioimportread, writestruc=read('h2o.gen',format='gen')
write('new.gen',struc*(3,3,3), format='gen')
write('POSCAR',struc*(3,3,3), format='vasp')ASE could handle almost all file format in the major codes.
For more information, please visit the following link: https://wiki.fysik.dtu.dk/ase/ase/io/io.html
Sometimes, one might wants to cut the crystal structure along some direction and then make the supercell. Below is an example of doing so.
fromase.ioimportread, writefromaseimportgeometryfromase.build.supercellsimportmake_supercellimportnumpyasnp#Read structure from POSCAR, this is ase.atom objectstruc=read('gra.vasp',format='vasp')
#make supercell hereP=np.array([[1,-1,0],[1,1,0],[0,0,1]])*2gra1=make_supercell(struc, P)
#After the lattice transformation#the supercell might have unpleasant shape such as #[ 0, -1, 0]#[ 1, 0, 0]#[ 0, 0, 1]#let's apply another transformation herecell_par=gra1.get_cell_lengths_and_angles()
pos1=gra1.get_scaled_positions()
cell1=geometry.cell.cellpar_to_cell(cell_par)
gra1.set_cell(cell1)
gra1.set_scaled_positions(pos1)
#output in any format whichever you wantwrite('POSCAR',gra1, format='vasp')$ cat Pt_primitive.vasp
Ce1O2
1.000000000000000
22.95150000000000 0.000000000000000 0.000000000000000
11.47575000000000 19.87658205495854 0.000000000000000
17.78942000000002 10.27072642572731 29.05000121337461
Ce O Pt C
180 360 19 0
Direct
9.611989863766990e-09 9.608114408254931e-09 0.1075147502183935
-0.0003887364393597298 -2.165967138571812e-05 0.2167485546162756
-0.001305103780566391 -0.0001492816586775858 0.3256709071579755
9.610177008345655e-09 0.1666666816113916 0.1075147502183935
-0.0004910138572741807 0.1664581574855210 0.2168893242489501
...
...
fromase.ioimportreadfromase.build.supercellsimportmake_supercellimportnumpyasnpat=read("Pt_primitive.vasp", format="vasp")
print(at.get_cell())
P=np.array([[1,-1,0],[1,1,0],[-1/2,-1/2,1]])
at1=make_supercell(at, P)
print(at1.get_cell())
at1.write("2.vasp", format='vasp', vasp5=True, direct=True)[22.9515 22.9515 35.57884 60. 60. 60. ]
[22.9515 39.75316411 29.05760871 88.68889365 90. 90. ]
Tips: Since some codes are changing their file formats from time to time in the development stage, one has to check if it works before using it as the script.