embasi 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- embasi/__init__.py +4 -0
- embasi/asi_default_callbacks.py +126 -0
- embasi/atoms_embedding_asi.py +669 -0
- embasi/basis_info.py +109 -0
- embasi/embedding.py +749 -0
- embasi/parallel_utils.py +104 -0
- embasi/roothan_hall_eigensolver.py +85 -0
- embasi/roothan_hall_eigensolver_scalapack.py +288 -0
- embasi-0.1.0.dist-info/METADATA +52 -0
- embasi-0.1.0.dist-info/RECORD +13 -0
- embasi-0.1.0.dist-info/WHEEL +5 -0
- embasi-0.1.0.dist-info/licenses/LICENSE +21 -0
- embasi-0.1.0.dist-info/top_level.txt +1 -0
embasi/__init__.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from ctypes import POINTER, byref, c_int, c_int64, c_int32, c_bool, \
|
|
2
|
+
c_char_p, c_double, c_void_p, CFUNCTYPE, py_object, \
|
|
3
|
+
cast, byref, Structure
|
|
4
|
+
from asi4py.pyasi import triang2herm_inplace, triang_packed2full_hermit
|
|
5
|
+
from mpi4py import MPI
|
|
6
|
+
import ctypes
|
|
7
|
+
|
|
8
|
+
def dm_saving_callback(aux, iK, iS, descr, data, matrix_descr_ptr):
|
|
9
|
+
"""Default callback for saving density matrices
|
|
10
|
+
|
|
11
|
+
Callback function from ASI to be registered and invoked by
|
|
12
|
+
a given QM code. Saves density matrices from a given ASI_run()
|
|
13
|
+
call to a dictionary of np.ndarray arrays, indexed by the
|
|
14
|
+
number of density matrices exported, k-point, and spin channel.
|
|
15
|
+
|
|
16
|
+
Code derived from the default saving callback from asi4py
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
aux: Object
|
|
21
|
+
Auxiliary object passed to callback
|
|
22
|
+
iK: c_int
|
|
23
|
+
k-point index of matrix
|
|
24
|
+
iS: c_int
|
|
25
|
+
Spin channel index of matrix
|
|
26
|
+
descr: c_types.POINTER(c_int)
|
|
27
|
+
Pointer to BLACS descriptor of matrix
|
|
28
|
+
data: c_types.POINTER
|
|
29
|
+
Pointer to dble/cdble matrix
|
|
30
|
+
matrix_descr_ptr: c_types.POINTER(c_int)
|
|
31
|
+
Numerical value indexing matrix shape (See: ASI docs)
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
asi, storage_dict, cnt_dict, label = cast(aux, py_object).value
|
|
37
|
+
|
|
38
|
+
if asi.is_hamiltonian_real:
|
|
39
|
+
data_shape = (asi.n_basis,asi.n_basis)
|
|
40
|
+
else:
|
|
41
|
+
data_shape = (asi.n_basis,asi.n_basis, 2)
|
|
42
|
+
|
|
43
|
+
if (matrix_descr_ptr.contents.storage_type not in {1,2}):
|
|
44
|
+
data = asi.scalapack.gather_numpy(descr, data, data_shape)
|
|
45
|
+
elif (matrix_descr_ptr.contents.storage_type in {1,2}):
|
|
46
|
+
assert not descr, """default_saving_callback supports only dense full
|
|
47
|
+
ScaLAPACK arrays"""
|
|
48
|
+
assert matrix_descr_ptr.contents.matrix_type == 1, \
|
|
49
|
+
"Triangular packed storage is supported only for hermitian matrices"
|
|
50
|
+
|
|
51
|
+
uplo = {1:'L',2:'U'}[matrix_descr_ptr.contents.storage_type]
|
|
52
|
+
data = triang_packed2full_hermit(data, asi.n_basis,
|
|
53
|
+
asi.is_hamiltonian_real, uplo)
|
|
54
|
+
|
|
55
|
+
if data is not None:
|
|
56
|
+
asi.dm_count += 1
|
|
57
|
+
assert len(data.shape) == 2
|
|
58
|
+
storage_dict[(asi.dm_count, iK, iS)] = data.copy()
|
|
59
|
+
|
|
60
|
+
except Exception as eee:
|
|
61
|
+
print(f"""Something happened in ASI default_saving_callback
|
|
62
|
+
{label}: {eee}\nAborting...""")
|
|
63
|
+
MPI.COMM_WORLD.Abort(1)
|
|
64
|
+
|
|
65
|
+
def ham_saving_callback(aux, iK, iS, descr, data, matrix_descr_ptr):
|
|
66
|
+
"""Default callback for saving hamiltonian matrices
|
|
67
|
+
|
|
68
|
+
Callback function from ASI to be registered and invoked by
|
|
69
|
+
a given QM code. Saves density matrices from a given ASI_run()
|
|
70
|
+
call to a dictionary of np.ndarray arrays, indexed by the
|
|
71
|
+
number of hamiltonian matrices exported, k-point, and spin channel.
|
|
72
|
+
|
|
73
|
+
Code derived from the default saving callback from asi4py
|
|
74
|
+
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
aux: Object
|
|
78
|
+
Auxiliary object passed to callback
|
|
79
|
+
iK: c_int
|
|
80
|
+
k-point index of matrix
|
|
81
|
+
iS: c_int
|
|
82
|
+
Spin channel index of matrix
|
|
83
|
+
descr: c_types.POINTER(c_int)
|
|
84
|
+
Pointer to BLACS descriptor of matrix
|
|
85
|
+
data: c_types.POINTER
|
|
86
|
+
Pointer to dble/cdble matrix
|
|
87
|
+
matrix_descr_ptr: c_types.POINTER(c_int)
|
|
88
|
+
Numerical value indexing matrix shape (See: ASI docs)
|
|
89
|
+
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
asi, storage_dict, cnt_dict, label = cast(aux, py_object).value
|
|
94
|
+
|
|
95
|
+
if asi.is_hamiltonian_real:
|
|
96
|
+
data_shape = (asi.n_basis,asi.n_basis)
|
|
97
|
+
else:
|
|
98
|
+
data_shape = (asi.n_basis,asi.n_basis, 2)
|
|
99
|
+
|
|
100
|
+
# ASI_STORAGE_TYPE_TRIL,ASI_STORAGE_TYPE_TRIU
|
|
101
|
+
if (matrix_descr_ptr.contents.storage_type not in {1,2}):
|
|
102
|
+
data = asi.scalapack.gather_numpy(descr, data, data_shape)
|
|
103
|
+
elif (matrix_descr_ptr.contents.storage_type in {1,2}): #
|
|
104
|
+
assert not descr, """default_saving_callback supports only dense
|
|
105
|
+
full ScaLAPACK arrays"""
|
|
106
|
+
assert matrix_descr_ptr.contents.matrix_type == 1, \
|
|
107
|
+
"Triangular packed storage is supported only for hermitian matrices"
|
|
108
|
+
uplo = {1:'L',2:'U'}[matrix_descr_ptr.contents.storage_type]
|
|
109
|
+
data = triang_packed2full_hermit(data, asi.n_basis,
|
|
110
|
+
asi.is_hamiltonian_real, uplo)
|
|
111
|
+
|
|
112
|
+
if data is not None:
|
|
113
|
+
assert len(data.shape) == 2
|
|
114
|
+
if asi.ham_count < 3:
|
|
115
|
+
asi.ham_count = asi.ham_count + 1
|
|
116
|
+
storage_dict[(asi.ham_count, iK, iS)] = data.copy()
|
|
117
|
+
else:
|
|
118
|
+
storage_dict.pop((1, iK, iS))
|
|
119
|
+
storage_dict[(1, iK, iS)] = storage_dict[(2, iK, iS)].copy()
|
|
120
|
+
storage_dict[(2, iK, iS)] = storage_dict[(3, iK, iS)].copy()
|
|
121
|
+
storage_dict[(3, iK, iS)] = data.copy()
|
|
122
|
+
|
|
123
|
+
except Exception as eee:
|
|
124
|
+
print(f"""Something happened in ASI default_saving_callback {label}:
|
|
125
|
+
{eee}\nAborting...""")
|
|
126
|
+
MPI.COMM_WORLD.Abort(1)
|