Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus: make tiling more robust #1432

Merged
merged 4 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
274 changes: 273 additions & 1 deletion nexus/bin/nxs-test
Original file line number Diff line number Diff line change
Expand Up @@ -2410,12 +2410,283 @@ def machines():



def structure():
# divert logging function
nlog_divert()

nlabel('imports')
from generic import obj
from structure import Structure,Crystal
from structure import generate_structure
from structure import read_structure


nlabel('definitions')
def structure_same(s1,s2):
keys = ('units','elem','pos','axes','kpoints','kweights','kaxes')
o1 = s1.obj(keys)
o2 = s2.obj(keys)
return object_eq(o1,o2)
#end def structure_same

def structure_diff(s1,s2):
keys = ('units','elem','pos','axes','kpoints','kweights','kaxes')
o1 = s1.obj(keys)
o2 = s2.obj(keys)
return object_diff(o1,o2,full=True)
#end def structure_diff


nlabel('empty_init')
s1 = Structure()
s2 = generate_structure('empty')
nassert(object_eq(s1,s2))


nlabel('ref_inputs')
ref_in = obj()
ref_in.diamond_prim = obj(
units = 'A',
axes = [[1.785, 1.785, 0. ],
[0. , 1.785, 1.785],
[1.785, 0. , 1.785]],
elem = ['C','C'],
pos = [[0. , 0. , 0. ],
[0.8925, 0.8925, 0.8925]],
)
ref_in.diamond_conv = obj(
units = 'A',
axes = [[3.57, 0 , 0. ],
[0. , 3.57, 0. ],
[0 , 0. , 3.57]],
elem = ['C','C','C','C','C','C','C','C'],
pos = [[0.0000, 0.0000, 0.0000],
[0.8925, 0.8925, 0.8925],
[0.0000, 1.7850, 1.7850],
[0.8925, 2.6775, 2.6775],
[1.7850, 0.0000, 1.7850],
[2.6775, 0.8925, 2.6775],
[1.7850, 1.7850, 0.0000],
[2.6775, 2.6775, 0.8925]],
)
ref_in.wurtzite_prim = obj(
units = 'A',
axes = [[ 3.350, 0.00000000, 0.00],
[-1.675, 2.90118510, 0.00],
[ 0.000, 0.00000000, 5.22]],
elem = ['Zn','O','Zn','O'],
pos = [[0.00000000e+00, 0.00000000e+00, 3.26250000e+00],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[1.67500000e+00, 9.67061701e-01, 6.52500000e-01],
[1.67500000e+00, 9.67061701e-01, 2.61000000e+00]],
)
ref_in.oxygen_prim = obj(
units = 'A',
axes = [[ 2.70150000e+00, -1.71450000e+00, 0.00000000e+00],
[ 2.70150000e+00, 1.71450000e+00, 0.00000000e+00],
[-3.43801471e+00, 0.00000000e+00, 3.74799291e+00]],
elem = ['O','O'],
pos = [[ 0., 0., 0.575],
[ 0., 0., -0.575]],
)
ref_in.CuO_prim = obj(
units = 'A',
axes = [[ 2.34150000e+00, -1.71100000e+00, 0.00000000e+00],
[ 2.34150000e+00, 1.71100000e+00, 0.00000000e+00],
[-8.49894838e-01, 0.00000000e+00, 5.05708046e+00]],
elem = ['Cu','O','Cu','O'],
pos = [[ 1.17075 , 0.8555 , 0. ],
[-0.21247371, 1.430396, 1.26427011],
[ 0.74580258, 2.5665 , 2.52854023],
[ 1.70407887, 0.280604, 3.79281034]],
)
ref_in.Ca2CuO3_prim = obj(
units = 'A',
axes = [[ 1.885, 1.625, -6.115],
[-1.885, 1.625, 6.115],
[ 1.885, -1.625, 6.115]],
elem = ['Cu','O','O','O','Ca','Ca'],
pos = [[0.000, 0.000, 0.000],
[1.885, 0.000, 0.000],
[0.000, 0.000, 1.960],
[0.000, 0.000, 10.270],
[0.000, 0.000, 4.290],
[0.000, 0.000, 7.940]],
)
ref_in.La2CuO4_prim = obj(
units = 'A',
axes = [[ 1.9045, 1.9045, -6.5845],
[-1.9045, 1.9045, 6.5845],
[ 1.9045, -1.9045, 6.5845]],
elem = ['Cu','O','O','O','O','La','La'],
pos = [[ 0. , 0. , 0. ],
[ 0.95225 , 0.95225 , -3.29225 ],
[-0.95225 , 0.95225 , 3.29225 ],
[ 0.346619, -0.346619, 1.198379],
[-0.346619, 0.346619, -1.198379],
[ 0.689429, -0.689429, 2.383589],
[-0.689429, 0.689429, -2.383589]],
)
ref_in.graphene_prim = obj(
units = 'A',
axes = [[ 2.462, 0.00000000, 0.00],
[-1.231, 2.13215454, 0.00],
[ 0.000, 0.00000000, 15.00]],
elem = ['C','C'],
pos = [[0. , 0. , 0. ],
[1.231, 0.71071818, 0. ]],
)


nlabel('direct_init')
ref = obj()
for name,inputs in ref_in.iteritems():
ref[name] = Structure(**inputs)
#end for


nlabel('generate_init')
gen = obj()
for name,inputs in ref_in.iteritems():
gen[name] = generate_structure(**inputs)
#end for


nlabel('crystal_init')
crys = obj()
for (latt,cell),inputs in Crystal.known_crystals.iteritems():
s = generate_structure(structure=latt,cell=cell)
crys[latt+'_'+cell] = s
#end for


nlabel('check_generate_init')
for name,s in ref.iteritems():
nassert(structure_same(s,gen[name]))
#end for


nlabel('check_crystal_init')
for name,s in ref.iteritems():
nassert(structure_same(s,crys[name]))
#end for


nlabel('diagonal_tiling')
diag_tilings = [
(1, 1, 1),
(1, 2, 3),
(1, 2, 4),
(1, 3, 1),
(1, 3, 2),
(1, 3, 3),
(1, 5, 3),
(1, 5, 5),
(1, 5, 6),
(2, 1, 2),
(2, 1, 3),
(2, 2, 2),
(2, 3, 1),
(2, 3, 2),
(2, 3, 3),
(2, 4, 4),
(2, 5, 1),
(2, 5, 2),
(2, 5, 3),
(3, 1, 1),
(3, 1, 2),
(3, 1, 3),
(3, 2, 1),
(3, 2, 3),
(3, 3, 6),
(4, 6, 4),
(5, 5, 1),
(5, 5, 5),
(6, 2, 6),
(6, 3, 1),
(6, 3, 6),
(6, 4, 6),
(6, 6, 4),
]
for name,s in ref.iteritems():
for tvec in diag_tilings:
st = s.tile(tvec)
st.check_tiling()
#end for
#end for


nlabel('matrix_tiling')
matrix_tilings = [
(-3,-2, 0,-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3,-2,-1),
( 3, 0, 2, 3,-2,-3,-3,-2, 1),
( 3, 1, 1,-2,-1,-3, 3, 1, 0),
( 3, 2,-3,-2, 2, 1, 1, 0,-1),
( 3, 2,-2,-1,-3,-1, 3, 3, 2),
( 3, 2, 3,-1, 2, 2, 0,-1, 0),
( 3, 3,-1, 0,-3, 2,-3,-1, 0),
( 3, 3, 1,-3,-2,-3, 2,-3, 3),
( 3, 3, 1, 1,-2, 2, 2,-2, 0),
]
#for name in sorted(ref.keys()):
for name in ['diamond_prim']:
s = ref[name]
npass = 0
for tmat in matrix_tilings:
tmat = array(tmat,dtype=int)
tmat.shape = 3,3
st = s.tile(tmat)
st.check_tiling()
#end for
#end for

# restore logging function
nlog_restore()
#end def structure



def pwscf_input():
# divert logging function
nlog_divert()

nlabel('directories')
loc_test_dir = os.path.join(test_dir,'pwscf_input')
loc_test_dir = os.path.join(test_dir,'pwscf_input')
sample_inputs = os.path.join(loc_test_dir,'sample_inputs')
sample_structures = os.path.join(loc_test_dir,'sample_structures')

Expand Down Expand Up @@ -2974,6 +3245,7 @@ NexusTest( generic_extensions )
NexusTest( nexus_imports )
NexusTest( settings_operation , 'settings' )
NexusTest( machines )
NexusTest( structure )
NexusTest( pwscf_input )

for label in example_information.keys():
Expand Down
Loading