-
Notifications
You must be signed in to change notification settings - Fork 0
/
asekk.py
66 lines (55 loc) · 1.68 KB
/
asekk.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
import numpy as np
from math import cos, sin, pi
#####################################
#
# rotate - rotate 'vector' around 'axis'
# by angle 'alpha' in respect to 'origin'
#
#######################################
def rotate(vector, alpha, axis='z', origin=[0.0,0.0,0.0]):
a=(alpha*pi)/180.0
o=np.array(origin)
v=np.array(vector)
v1=np.add(v,-o)
matrix = []
if(axis=='z'):
matrix.append([ cos(a),-sin(a), 0.0 ])
matrix.append([ sin(a), cos(a), 0.0 ])
matrix.append([ 0.0 , 0.0 , 1.0 ])
elif(axis=='x'):
matrix.append([ 1.0 , 0.0 , 0.0 ])
matrix.append([ 0.0 , cos(a),-sin(a)])
matrix.append([ 0.0 , sin(a), cos(a)])
elif(axis=='y'):
matrix.append([ cos(a), 0.0 , sin(a)])
matrix.append([ 0.0 , 1.0 , 0.0 ])
matrix.append([-sin(a), 0.0 , cos(a)])
m = np.array(matrix)
v2=np.dot(m,v1)
return np.add(o,v2)
#####################################
#
# rotate secected atoms
#
#######################################
def rotate_atoms(atoms, alpha, fromto=[-1,-1], axis='z', origin=[0.0,0.0,0.0]):
p=atoms.arrays['positions']
n=len(p)
ifrom, ito = 0,0
if(fromto[0]==-1 and fromto[1]==-1):
ifrom = 1
ito = len(atoms)
else:
ifrom = fromto[0]
ito = fromto[1]
for i in range(ifrom-1,ito):
p[i] = rotate(p[i],alpha,axis=axis,origin=origin)
# p[i] = asekk.rotate(p[i],alpha,axis=axis,origin=origin)
#####################################
#
# print Atoms in bas format
#
#######################################
def write_bas(atoms):
p=atoms.arrays['positions']
print("position")