|
def find_neighbors(cell_bra: Union[PrimitiveCell, SuperCell], |
|
cell_ket: Union[PrimitiveCell, SuperCell] = None, |
|
a_max: int = 0, |
|
b_max: int = 0, |
|
c_max: int = 0, |
|
max_distance: float = 1.0) -> List[namedtuple]: |
|
""" |
|
Find neighbours between the (0, 0, 0) cell of model_bra and nearby cells of |
|
cell_ket up to given cutoff distance. |
|
|
|
NOTE: only neighbours with distance > 0 will be returned. |
|
|
|
The searching range of nearby cells is: |
|
[-a_max, a_max] * [-b_max, b_max] * [-c_max, c_max]. |
|
|
|
The named tuples have four attributes: rn for cell index, pair for orbital |
|
indices, rij for Cartesian coordinates of displacement vector in nm and |
|
distance for the norm of rij. |
|
|
|
:param cell_bra: the 'bra' primitive cell or supercell |
|
:param cell_ket: the 'ket' primitive cell or supercell |
|
default to pc_ket if not set |
|
:param a_max: upper bound of range on a-axis |
|
:param b_max: upper bound of range on b-axis |
|
:param c_max: upper bound of range on c-axis |
|
:param max_distance: cutoff distance in NM |
|
:return: list of neighbors as named tuples |
|
:raise PCOrbEmptyError: if cell_bra or cell_ket does not contain orbitals |
|
""" |
|
if cell_ket is None: |
|
cell_ket = cell_bra |
|
|
|
# Check for number of orbitals |
|
if isinstance(cell_bra, PrimitiveCell): |
|
cell_bra.verify_orbitals() |
|
cell_ket.verify_orbitals() |
|
|
|
# Get orbital positions |
|
if isinstance(cell_bra, PrimitiveCell): |
|
pos_bra = cell_bra.orb_pos_nm |
|
pos_ket = cell_ket.orb_pos_nm |
|
else: |
|
pos_bra = cell_bra.get_orb_pos() |
|
pos_ket = cell_ket.get_orb_pos() |
|
|
|
# Get lattice vectors of cell_ket |
|
if isinstance(cell_ket, PrimitiveCell): |
|
lat_ket = cell_ket.lat_vec |
|
else: |
|
lat_ket = cell_ket.sc_lat_vec |
This issue comes from a Codex global scan of deepmodeling/tbplas at commit 4d3652b.
Severity: Medium
The signature allows
cell_braandcell_ketto be eitherPrimitiveCellorSuperCell, but the implementation dispatches position access mostly from the type ofcell_bra. Mixed calls such as primitive-to-supercell or supercell-to-primitive can therefore call attributes/methods that do not exist oncell_ket.Code reference:
tbplas/tbplas/builder/advanced.py
Lines 402 to 451 in 4d3652b
Suggested fix: resolve orbital positions independently for
cell_braandcell_ket, or narrow the accepted API and validate unsupported mixed-type calls explicitly.