|
|
| Line 3: |
Line 3: |
| [[Image:Dire2cart.tgz]] | | [[Image:Dire2cart.tgz]] |
|
| |
|
| #!/usr/bin/env python
| | 1: Download and uncompress Dire2cart.tgz: tar -zxf Dire2cart.tgz ; |
| # -*- coding: utf-8 -*-
| | 2: Copy dire2cart.py to bin folder: cp dire2cart.py ~/bin |
| #Convert direct coordinates to cartesian Writen By Qiang
| | 3: chmod u+x ~/bin/dire2cart.py |
|
| |
|
| import subprocess
| | (By default, this script will convert POSCAR only. If you want convert CONTCAR, copy CONTCAR to POSCAR and run it. |
| | Or you can edit the script, change POSCAR to CONTCAR in line 8) |
|
| |
|
| subprocess.call('rm POSCAR_C -f', shell = True)
| | Even though you can do it from p4vasp, with this you can convert them in batch. |
| file_read = open('POSCAR', 'r')
| |
| | |
| line = file_read.readlines()
| |
| a1 = float(line[2].split()[0])
| |
| a2 = float(line[3].split()[0])
| |
| a3 = float(line[4].split()[0])
| |
| b1 = float(line[2].split()[1])
| |
| b2 = float(line[3].split()[1])
| |
| b3 = float(line[4].split()[1])
| |
| z1 = float(line[2].split()[2])
| |
| z2 = float(line[3].split()[2])
| |
| z3 = float(line[4].split()[2])
| |
| | |
| num_atoms = sum([int(x) for x in line[6].split()])
| |
| | |
| x_cartesian = []
| |
| y_cartesian = []
| |
| z_cartesian = []
| |
| tf = []
| |
| | |
| for i in range(9,num_atoms+9):
| |
| x_cartesian.append(float(line[i].split()[0]) * a1 + float(line[i].split()[1]) * a2 + float(line[i].split()[2]) * a3)
| |
| y_cartesian.append(float(line[i].split()[0]) * b1 + float(line[i].split()[1]) * b2 + float(line[i].split()[2]) * b3)
| |
| z_cartesian.append(float(line[i].split()[0]) * z1 + float(line[i].split()[1]) * z2 + float(line[i].split()[2]) * z3)
| |
| tf.append((line[i].split()[3]))
| |
|
| |
| file_out = open('POSCAR_C', 'a')
| |
| | |
| for i in range(0,8):
| |
| file_out.write(line[i].rstrip() + '\n')
| |
| file_out.write('Cartesian' + '\n')
| |
| | |
| for i in range(0,len(x_cartesian)):
| |
| file_out.write("%+-3.10f %+-3.10f %+-3.10f %s %s %s\n"
| |
| %(x_cartesian[i], y_cartesian[i], z_cartesian[i], tf[i], tf[i], tf[i]))
| |
| | |
| file_read.close()
| |
| file_out.close()
| |
| | |
| print 'POSCAR with Cartesian Coordiations is named as POSCAR_C'
| |
go back to Main Page, Computational Resources, Scripts, Scripts for VASP
File:Dire2cart.tgz
1: Download and uncompress Dire2cart.tgz: tar -zxf Dire2cart.tgz ;
2: Copy dire2cart.py to bin folder: cp dire2cart.py ~/bin
3: chmod u+x ~/bin/dire2cart.py
(By default, this script will convert POSCAR only. If you want convert CONTCAR, copy CONTCAR to POSCAR and run it.
Or you can edit the script, change POSCAR to CONTCAR in line 8)
Even though you can do it from p4vasp, with this you can convert them in batch.