/
test_neighbors.py
110 lines (87 loc) · 3.25 KB
/
test_neighbors.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
import pytest
import os
import numpy as np
import pyscal.core as pc
import pyscal.crystal_structures as pcs
def test_neighbors_system():
#create some atoms
atoms, boxdims = pcs.make_crystal('bcc', repetitions = [6, 6, 6])
sys = pc.System()
sys.box = boxdims
sys.atoms = atoms
#test that atoms are set properly
assert len(sys.atoms) == 432
#then lets find neighbors
#cutoff method - first shell only
sys.find_neighbors(method = 'cutoff', cutoff=0.867)
#any atom should have 8 neighbors
atoms = sys.atoms
assert atoms[0].coordination == 8
sys.reset_neighbors()
#cutoff method - second shell
sys.find_neighbors(method = 'cutoff', cutoff=1.1)
#any atom should have 8 neighbors
atoms = sys.atoms
assert atoms[0].coordination == 14
#cutoff method - third shell
sys.find_neighbors(method = 'cutoff', cutoff=1.5)
#any atom should have 8 neighbors
atoms = sys.atoms
assert atoms[0].coordination == 26
sys.reset_neighbors()
#voronoi method - first shell only
sys.find_neighbors(method = 'voronoi')
#any atom should have 8 neighbors
atoms = sys.atoms
assert atoms[0].coordination == 14
assert np.round(sys.get_distance(atoms[0], atoms[1]), decimals=2) == 0.87
def test_neighbors_system_filter():
#create some atoms
atoms, boxdims = pcs.make_crystal('bcc', repetitions = [5, 5, 5])
sys = pc.System()
sys.box = boxdims
sys.atoms = atoms
sys.find_neighbors(method = 'cutoff', cutoff=0.867)
#any atom should have 8 neighbors
atoms = sys.atoms
assert atoms[0].coordination == 8
#now we take all the neighbors of atom0 and replace half of
#them with a different type
neighs = atoms[0].neighbors
#replace the neighs
atoms[neighs[0]].type = 2
atoms[neighs[1]].type = 2
#now set these atoms back
#for atom in atoms:
sys.set_atom(atoms[neighs[0]])
sys.set_atom(atoms[neighs[1]])
#recalculate neighbors with filter
sys.find_neighbors(method = 'cutoff', cutoff=0.867, filter='type')
#any atom should have 8 neighbors
atoms = sys.atoms
assert atoms[0].coordination == 6
def test_neighbors_diamond():
atoms, box = pcs.make_crystal(structure="diamond", lattice_constant=5.67, repetitions=(6,6,6))
sys = pc.System()
sys.box = box
sys.atoms = atoms
sys.find_diamond_neighbors()
sys.calculate_q([4,6], averaged=True)
assert (np.mean(sys.get_qvals(4))-0.19094065395649326) < 1E-2
assert (np.mean(sys.get_qvals(6))-0.5745242597140696) < 1E-2
atoms, box = pcs.make_crystal(structure="fcc", lattice_constant=4.07, repetitions=(6,6,6))
sys = pc.System()
sys.box = box
sys.atoms = atoms
sys.find_neighbors(method="cutoff", cutoff=0)
sys.calculate_q([4,6], averaged=True)
assert (np.mean(sys.get_qvals(4))-0.19094065395649326) < 1E-2
assert (np.mean(sys.get_qvals(6))-0.5745242597140696) < 1E-2
atoms, box = pcs.make_crystal(structure="fcc", lattice_constant=4.07, repetitions=(6,6,6))
sys = pc.System()
sys.box = box
sys.atoms = atoms
sys.find_diamond_neighbors()
sys.calculate_q([4,6], averaged=True)
assert (np.mean(sys.get_qvals(4))-0.210287193019979) < 1E-2
assert (np.mean(sys.get_qvals(6))-0.2350776015575979) < 1E-2