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
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
go back to [[Main Page]], [[Computational Resources]], [[Scripts]], [[Scripts for VASP]]  
go back to [[Main Page]], [[Computational Resources]], [[Scripts]], [[Scripts for VASP]]  
[[Dire2cart.tgz]]


#!/usr/bin/env python
[[Image:Dire2cart.tgz]]
# -*- coding: utf-8 -*-
#Convert direct coordinates to cartesian Writen By Qiang


import subprocess
1: Download and uncompress Dire2cart.tgz: tar -zxf Dire2cart.tgz ;


subprocess.call('rm POSCAR_C -f', shell = True)
2: Copy dire2cart.py to bin folder: cp dire2cart.py ~/bin  ;
file_read = open('POSCAR', 'r')


line = file_read.readlines()
3: chmod u+x ~/bin/dire2cart.py
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()])
(By default, this script will convert POSCAR only)


x_cartesian = []
If you want convert CONTCAR,
y_cartesian = []
z_cartesian = []
tf = []


for i in range(9,num_atoms+9):
copy CONTCAR to POSCAR and run it.  
    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):
Or
    file_out.write(line[i].rstrip() + '\n')
file_out.write('Cartesian' + '\n')


for i in range(0,len(x_cartesian)):
you can edit the script, change POSCAR to CONTCAR in line 8.
    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()
Even though you can do it from p4vasp, with this you can convert them in batch.
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.