Dire2cart.py: Difference between revisions

From Wiki
Jump to navigation Jump to search
QiangLi (talk | contribs)
No edit summary
QiangLi (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
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 -*-
#Convert direct coordinates to cartesian Writen By Qiang


import subprocess
2: Copy dire2cart.py to bin folder: cp dire2cart.py ~/bin  ;


subprocess.call('rm POSCAR_C -f', shell = True)
3: chmod u+x ~/bin/dire2cart.py
file_read = open('POSCAR', 'r')


line = file_read.readlines()
(By default, this script will convert POSCAR only)
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()])
If you want convert CONTCAR,


x_cartesian = []
copy CONTCAR to POSCAR and run it.
y_cartesian = []
z_cartesian = []
tf = []


for i in range(9,num_atoms+9):
Or
    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):
you can edit the script, change POSCAR to CONTCAR in line 8.
    file_out.write(line[i].rstrip() + '\n')
file_out.write('Cartesian' + '\n')


for i in range(0,len(x_cartesian)):
Even though you can do it from p4vasp, with this you can convert them in batch.
    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'

Latest revision as of 10:14, 23 March 2016

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.