-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_neighbors.py
78 lines (62 loc) · 2.14 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
import pytest
import os,sys,inspect
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.atoms = atoms
sys.box = boxdims
#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 = [2, 2, 2])
sys = pc.System()
sys.atoms = atoms
sys.box = boxdims
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