Dire2cart.py: Difference between revisions

From Wiki
Jump to navigation Jump to search
New page: #!/usr/bin/env python # -*- coding: utf-8 -*- #Convert direct coordinates to cartesian Writen By Qiang import subprocess subprocess.call('rm POSCAR_C -f', shell = True) file_read = open...
 
QiangLi (talk | contribs)
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
#!/usr/bin/env python
go back to [[Main Page]], [[Computational Resources]], [[Scripts]], [[Scripts for VASP]]
# -*- coding: utf-8 -*-
#Convert direct coordinates to cartesian Writen By Qiang


import subprocess
[[Image:Dire2cart.tgz]]


subprocess.call('rm POSCAR_C -f', shell = True)
1: Download and uncompress Dire2cart.tgz: tar -zxf Dire2cart.tgz ;
file_read = open('POSCAR', 'r')


line = file_read.readlines()
2: Copy dire2cart.py to bin folder: cp dire2cart.py ~/bin  ;
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()])
3: chmod u+x ~/bin/dire2cart.py


x_cartesian = []
(By default, this script will convert POSCAR only)
y_cartesian = []
z_cartesian = []
tf = []


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


for i in range(0,len(x_cartesian)):
Or
    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()
you can edit the script, change POSCAR to CONTCAR in line 8.
file_out.close()


print 'POSCAR with Cartesian Coordiations is named as POSCAR_C'
Even though you can do it from p4vasp, with this you can convert them in batch.

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.