Skip to content

[Code scan] Preserve documented 3x3 cell matrices instead of collapsing them to diagonals #2447

Description

@njzjz

This issue is a Codex global repository scan finding for deepmodeling/reacnetgenerator at commit 4fa8e2b.

ReacNetGenerator.__init__() documents cell as accepting (3,3), (3,), or (9,) input, but the current normalization treats any object with len(cell) == 3 as a vector and passes it to np.diag().

Relevant code:

if self.cell is not None:
if len(self.cell) == 9:
self.cell = np.array(self.cell).reshape((3, 3))
elif len(self.cell) == 3:
self.cell = np.diag(self.cell)
else:
raise RuntimeError(
"cell must be (3,3) array_like or (3,) array_like or (9,) array_like"

For a normal 3x3 matrix such as [[1,0,0],[0,2,0],[0,0,3]], len(cell) == 3, so line 279 produces the 1-D vector [1, 2, 3] instead of preserving the matrix. Downstream coordinate-based PBC detection expects matrix indexing, e.g. Open Babel setup reads cell[0][0], cell[0][1], etc.

Downstream use:

-------
list[list[int]]
Connected atoms for each atom.
list[list[int]]
Bond orders for each atom. 12 is an aromatic bond.
"""
# Check if ASE mode is enabled
if self.use_ase:

Impact:

  • documented 3x3 cell inputs can be silently converted to the wrong shape
  • PBC bond perception can crash or use invalid geometry
  • users passing full triclinic or non-cubic cells through the Python API or CLI --cell can get incorrect behavior

Suggested fix:

Convert cell to a NumPy array first and branch on array.shape or array.size, preserving (3, 3), diagonalizing (3,), and reshaping flat (9,). Add regression tests for list-of-lists and flat 9-value cells.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions