-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdd_modes.py
73 lines (59 loc) · 2.25 KB
/
dd_modes.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
import sys
import numpy as np
# from os import listdir
# from os.path import isfile, join
from os.path import basename
from glob import glob
if len(sys.argv) < 4:
print('\nERROR: missing arguments.')
print('Please specify the directory where the modes are stored, then the amount of modes you wanna spot, then the number of the atom you are looking for in the file.\n')
sys.exit()
print('\n!! The format of the atom to be found is Ex: C182 for carbon and atom number 182 !!\n')
directory = sys.argv[1]
max_total = int(sys.argv[2])
find_atom = str(sys.argv[3])
all_files = glob(str(directory + '/mode_*.xyz'))
# all_files = [f for f in listdir(directory) if isfile(join(directory, f))]
print('Reading files\n')
final_of_final = []
lmodes_delta = []
for file in all_files:
with open(file) as fp:
xyz_data = fp.readlines()
xyz_data.pop(0)
xyz_data.pop(0)
atom_coord = []
n = 1
for data in xyz_data:
try:
name = '{}{}'.format(data.split()[0], n)
x_coord = float(data.split()[1])
y_coord = float(data.split()[2])
z_coord = float(data.split()[3])
position = np.sqrt((x_coord**2) + (y_coord**2) + (z_coord**2))
if name == find_atom:
atom_coord.append([position])
n += 1
except:
n = 0
delta_of_mode = max([np.ab(atom_coord[0] - i) for i in atom_coord])
lmodes_delta.append([file, delta_of_mode])
# all_xyz = np.array_split(atoms_coord, 30)
# all_xyz = np.asarray(all_xyz)
# a = (zip(*all_xyz))
# a = list(a)
# delta_list = []
# for atom in a:
# delta = float(max(map(lambda x: x[1], atom))) - float(min(map(lambda x: x[1], atom)))
# delta_list.append([atom[0][0], delta, file])
# final = sorted(delta_list, key=lambda x: x[1], reverse=True)
# final_of_final += final
print('Sorting atoms\n')
test = sorted(final_of_final, key=lambda x: x[1], reverse=True)
found_atom = []
for data in test:
if find_atom == data[0]:
found_atom.append(data)
sorted_found_atom = sorted(found_atom, key=lambda x: x[1], reverse=True)
for t in sorted_found_atom[:max_total]:
print('Mode: {}'.format(basename(t[2])), 'Atom: {}'.format(t[0]), 'Value: {:e} A'.format(t[1]))