-
Notifications
You must be signed in to change notification settings - Fork 2
/
cube_charhe_diff.py
70 lines (51 loc) · 1.35 KB
/
cube_charhe_diff.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
#coding:utf-8
import os
import re
import glob
import string
import math
import sys
import linecache
if len(sys.argv) != 4 :
print " Usage\n python cell2poscar.py n cellfile or all\n n is the number of the nonmovale atom\n all --all the cellfile in current directory will be coverted"
sys.exit()
else :
cube1 = sys.argv[1]
cube2 = sys.argv[2]
cube3 = sys.argv[3]
if not os.path.isfile(cube1) :
print cube1 + "doesn\'t exist"
sys.exit()
elif not os.path.isfile(cube2) :
print cube2 + "doesn\'t exist"
sys.exit()
elif not os.path.isfile(cube3) :
print cube3 + "doesn\'t exist"
sys.exit()
cube4_name = cube1[:-5] + "---char_diff" + ".cube"
cube = open(cube1,"r")
cube4 = open(cube4_name,"a")
for i , line in enumerate(cube) :
if len(line) < 10 and i > 6 :
x = i + 1
break
else :
cube4.write(line.rstrip() + "\n")
cube = open(cube2,"r")
for i , line in enumerate(cube) :
if len(line) < 10 and i > 6 :
y = i + 1
break
cube = open(cube3,"r")
for i , line in enumerate(cube) :
if len(line) < 10 and i > 6 :
z = i + 1
break
while (linecache.getline(cube1 , x)) :
i = str(float(linecache.getline(cube1 , x).rstrip())-float(linecache.getline(cube2 , y).rstrip())-float(linecache.getline(cube3 , z).rstrip())) + "\n"
cube4.write(i)
x = x + 1
y = y + 1
z = z + 1
cube4.close()
linecache.clearcache()