-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_dopant.py
133 lines (77 loc) · 2.78 KB
/
run_dopant.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import numpy as np
import numpy as np
import pandas as pd
import sys
import random
file_to_read = str(sys.argv[1])
cnt_in = int(sys.argv[2])
def read_datafile(file_in):
count = 0
with open(file_in) as f:
for line in f:
count +=1
if line.startswith('Atoms #'):
skip_lines = count
if line.startswith('Velocities'):
natoms = count - 3
df = pd.read_table(file_in, delim_whitespace=True, header=None, skiprows=skip_lines, nrows=natoms-skip_lines)
df = df.drop(columns=2)
df.columns = ['id', 'type', 'x', 'y', 'z', 'nx', 'ny', 'nz']
return df
def compute_distance(cnt_array, cnt_other_array):
dist_list = []
points = cnt_array
for j in range(0, len(cnt_other_array)):
single_point = cnt_other_array[j, :]
dist = np.sum(((points - single_point)**2), axis=1)
dist = np.sqrt(dist)
dist_list.append(dist)
return np.asarray(dist_list)
def locate_cnt(df, type_choose=22, random_var=True, **kwargs):
df_cnt = df.loc[df['type'] == type_choose]
df_other = df.loc[df['type'] != type_choose]
other_mat = df_other.loc[:, ['x', 'y', 'z']].as_matrix()
if random_var==True:
cnt_xyz = (df_cnt.loc[:, ['id', 'x', 'y', 'z']]).as_matrix()
len_cnt= int(len(cnt_xyz))
rand_num = random.randint(0, len_cnt)
cnt_choose = cnt_xyz[rand_num, :]
cnt_id = cnt_choose[0]
x_out = cnt_choose[1]
y_out = cnt_choose[2]
z_out = cnt_choose[3]
elif 'cnt_id' in kwargs:
cnt_id = kwargs['cnt_id']
df_choose = df.loc[df['id']==cnt_id]
cnt_choose = (df_choose.loc[:, ['x', 'y', 'z']]).as_matrix()
cnt_choose = cnt_choose.flatten()
x_out = cnt_choose[0]
y_out = cnt_choose[1]
z_out = cnt_choose[2]
else:
cnt_id = 0
x_out = 0
y_out = 0
z_out = 0
###this block of code to find difference between
pick_cnt = np.array([x_out, y_out, z_out])
dist_mat = np.linalg.norm((pick_cnt - other_mat), axis=1)
idx_mat = np.argmin(dist_mat)
print "troubleshoot"
print other_mat[idx_mat]
print dist_mat[idx_mat]
print "new coords: "
other_cords = other_mat[idx_mat]
new_cords = np.array([(0.5*pick_cnt[0] + 0.5*other_cords[0]), 1*(0.5*pick_cnt[1] + 0.5*other_cords[1]), 1*(0.5*pick_cnt[2] + 0.5*other_cords[2])])
print new_cords
return cnt_id, x_out, y_out, z_out
if __name__ == "__main__":
df = read_datafile(file_in=file_to_read)
if cnt_in == 0:
cnt_id, x_out, y_out, z_out = locate_cnt(df=df)
else:
cnt_id, x_out, y_out, z_out = locate_cnt(df=df, random_var=False, cnt_id=cnt_in)
print int(cnt_id)
print x_out
print y_out
print z_out