mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-01-03 10:06:01 +01:00
add the tests for the top-level Python API of sparse data
This commit is contained in:
parent
31ffa574ab
commit
0cadb4ea0b
@ -103,11 +103,25 @@ coords = [
|
||||
# write coordinates in the file
|
||||
trexio.write_nucleus_coord(test_file, coords)
|
||||
|
||||
point_group = 'B3U'
|
||||
|
||||
# write mo_num (needed later to write sparse mo_2e_int_eri integrals)
|
||||
trexio.write_mo_num(test_file, 600)
|
||||
|
||||
# write sparse data in the file
|
||||
num_integrals = 100
|
||||
indices = [i for i in range(num_integrals*4)]
|
||||
values = [(3.14 + float(i)) for i in range(num_integrals)]
|
||||
|
||||
trexio.write_mo_2e_int_eri(test_file, 0, num_integrals, indices, values)
|
||||
|
||||
|
||||
# write nucleus_point_group in the file
|
||||
point_group = 'B3U'
|
||||
|
||||
trexio.write_nucleus_point_group(test_file, point_group)
|
||||
|
||||
|
||||
# write nucleus_label in the file
|
||||
labels = [
|
||||
'C',
|
||||
'C',
|
||||
@ -122,7 +136,6 @@ labels = [
|
||||
'H',
|
||||
'H']
|
||||
|
||||
# write nucleus_label in the file
|
||||
trexio.write_nucleus_label(test_file,labels)
|
||||
|
||||
# close TREXIO file
|
||||
@ -147,6 +160,7 @@ assert trexio.has_nucleus_charge
|
||||
assert trexio.has_nucleus_coord
|
||||
assert trexio.has_nucleus_label
|
||||
assert trexio.has_nucleus_point_group
|
||||
assert trexio.has_mo_2e_int_eri
|
||||
|
||||
# read nucleus_num from file
|
||||
rnum = trexio.read_nucleus_num(test_file2)
|
||||
@ -189,6 +203,33 @@ np.testing.assert_array_almost_equal(rcoords_np, np.array(coords).reshape(nucleu
|
||||
# set doReshape to False to get a flat 1D array (e.g. when reading matrices like nuclear coordinates)
|
||||
#rcoords_reshaped_2 = trexio.read_nucleus_coord(test_file2, doReshape=False)
|
||||
|
||||
# read number of integrals already present in the file
|
||||
assert trexio.has_mo_2e_int_eri(test_file2)
|
||||
assert trexio.read_mo_2e_int_eri_size(test_file2)==num_integrals
|
||||
|
||||
# read sparse arrays on mo_2e_int_eri integrals
|
||||
buf_size = 60
|
||||
offset_file = 0
|
||||
# read full buf_size (i.e. the one that does not reach EOF)
|
||||
indices_sparse_np, value_sparse_np, read_buf_size, eof = trexio.read_mo_2e_int_eri(test_file2, offset_file, buf_size)
|
||||
print(f'First complete sparse read size: {read_buf_size}')
|
||||
#print(indices_sparse_np)
|
||||
assert not eof
|
||||
assert read_buf_size==buf_size
|
||||
assert indices_sparse_np[0][0]==0
|
||||
assert indices_sparse_np[read_buf_size-1][3]==read_buf_size*4-1
|
||||
offset_file += buf_size
|
||||
|
||||
# read incomplete buf_size (i.e. the one that does reach EOF)
|
||||
indices_sparse_np, value_sparse_np, read_buf_size, eof2 = trexio.read_mo_2e_int_eri(test_file2, offset_file, buf_size)
|
||||
print(f'Second incomplete sparse read size: {read_buf_size}')
|
||||
#print(indices_sparse_np)
|
||||
assert eof2
|
||||
assert read_buf_size==(num_integrals - buf_size)
|
||||
assert indices_sparse_np[0][0]==offset_file*4
|
||||
assert indices_sparse_np[read_buf_size-1][3]==(offset_file+read_buf_size)*4-1
|
||||
|
||||
|
||||
# read array of nuclear labels
|
||||
rlabels_2d = trexio.read_nucleus_label(test_file2, dim=nucleus_num)
|
||||
print(rlabels_2d)
|
||||
@ -200,10 +241,10 @@ rpoint_group = trexio.read_nucleus_point_group(test_file2)
|
||||
assert rpoint_group==point_group
|
||||
|
||||
# another way to read only if the variable exists
|
||||
if trexio.has_mo_num(test_file2):
|
||||
rmo_num = trexio.read_mo_num(test_file2)
|
||||
if trexio.has_ao_num(test_file2):
|
||||
rmo_num = trexio.read_ao_num(test_file2)
|
||||
else:
|
||||
print("Pass on reading the non-existing variable mo_num: checked")
|
||||
print("Pass on reading the non-existing variable ao_num: checked")
|
||||
|
||||
# close TREXIO file
|
||||
#trexio.close(test_file2)
|
||||
|
Loading…
Reference in New Issue
Block a user