-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadLength.py
34 lines (30 loc) · 1.06 KB
/
readLength.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
import numpy as np
import re
import math
def period_minus(a, b):
if abs(a-b)<0.5:
return abs(a-b)
else:
return 1-abs(a-b)
def read_bond_length(POSCAR, orderA, orderB, atom_number):
#orderA and orderB are the order of two atoms
#numbers of POSCAR
with open(POSCAR) as file:
line = file.readline()
line = file.readline()
paraA = float(file.readline().split()[0])
paraB = float(file.readline().split()[1])
paraC = float(file.readline().split()[2])
while not re.search(r"D", line) and not re.search(r"d", line):
line = file.readline()
atoms=[0]*atom_number
for i in range(atom_number):
atoms[i] = file.readline().split()
#print(type(atoms[orderB][2]))
A = list(map(float, atoms[orderA]))
B = list(map(float, atoms[orderB]))
#print(A)
#print(B)
length = math.sqrt(period_minus(A[0], B[0])**2*paraA**2 + period_minus(A[1], B[1])**2*paraB**2 + period_minus(A[2], B[2])**2*paraC**2)
print(length)
read_bond_length("POSCAR", 3, 9, 16)