-
Notifications
You must be signed in to change notification settings - Fork 1
/
coordinate.py
75 lines (66 loc) · 1.56 KB
/
coordinate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 9 16:07:58 2019
@author: Yaqiong Su
"""
import numpy as np
import pandas as pd
import linecache as lc
f1 = open('POSCAR','rb')
f2 = open('head','wb')
f3 = open('direct','wb')
f4 = open('lattice','wb')
i = 0
while True:
line = f1.readline()
i+=1
if i < 7:
f2.write(line)
if i == 7:
f2.write('Cartesian \n')
if i > 8:
f3.write(line)
if i > 300:
break
f1.close()
f2.close()
f3.close()
with open('head','rb') as f22:
i = 0
while True:
line = f22.readline()
i+=1
if i> 2 and i < 6:
f4.write(line)
if i > 300:
break
f4.close()
#with open('matrix','rb') as f33:
# for data in f33.readlines():
# data = data.strip('\n')
# nums = data.split()
# nums = [float(x) for x in nums]
# direct = np.array(nums)
# print direct
direct = np.loadtxt('direct')
print "direct coordinate"
print direct
lattice = np.loadtxt('lattice')
print "lattice"
print lattice
cartesian = np.dot(direct,lattice)
print"cartesian coordinate"
print cartesian
np.savetxt('cartesian',cartesian)
f5 = open('Cartesian_POSCAR','ab')
with open('head','rb') as f:
for lines in f.readlines():
f5.write(lines)
with open('cartesian','rb') as f0:
for lines in f0.readlines():
f5.write(lines)
f5.close()
print "Cartesian_POSCAR"
with open('Cartesian_POSCAR','rb') as f:
for lines in f.readlines():
print lines