What would you like GBOpt to do?
GBManipulator.displace_along_soft_modes() should return a single np.ndarray of atom positions and expose a mode_index parameter so callers can choose which soft phonon mode to displace along.
Environment
- GBOpt version: 0.0.1
- Python version: 3.12.11
- OS / platform: Mac OSX 26.4
Which part of the pipeline does this affect?
Motivation
Usability friction: displace_along_soft_modes() currently always returns a list[np.ndarray] — even when using the default num_children=1. Callers who treat the result as a single structured array (e.g., result["name"]) get a TypeError: list indices must be integers or slices, not str. The num_children parameter is the source of this mismatch: generating multiple children in a single call is better handled by the caller in a loop, since each call already involves significant computation (Delaunay triangulation, dynamical matrix calculation).
Additionally, GBOpt currently provides no way to displace along anything other than the softest mode. Exposing a mode_index parameter would allow callers to explore a range of soft modes without rewriting the internals.
Proposed behavior
# Default: displace along the softest mode, return one structure
displaced = manipulator.displace_along_soft_modes()
displaced["name"] # np.ndarray — no [0] indexing needed
# Select the second-softest mode
displaced = manipulator.displace_along_soft_modes(mode_index=1)
# Caller-controlled multi-child loop
children = [
manipulator.displace_along_soft_modes(mode_index=i)
for i in range(3)
]
Acceptance criteria
API / breaking-change impact
Alternatives considered
- Always return a list, fix the test — consistent return type but forces
result[0] for the common single-structure case.
- Squeeze based on
num_children — returns a single array when num_children=1, list otherwise; inconsistent return type makes type hints and callers harder to reason about.
- Add a
squeeze parameter — explicit but adds API surface for a distinction that disappears once num_children is removed.
What would you like GBOpt to do?
GBManipulator.displace_along_soft_modes()should return a singlenp.ndarrayof atom positions and expose amode_indexparameter so callers can choose which soft phonon mode to displace along.Environment
Which part of the pipeline does this affect?
Motivation
Usability friction:
displace_along_soft_modes()currently always returns alist[np.ndarray]— even when using the defaultnum_children=1. Callers who treat the result as a single structured array (e.g.,result["name"]) get aTypeError: list indices must be integers or slices, not str. Thenum_childrenparameter is the source of this mismatch: generating multiple children in a single call is better handled by the caller in a loop, since each call already involves significant computation (Delaunay triangulation, dynamical matrix calculation).Additionally, GBOpt currently provides no way to displace along anything other than the softest mode. Exposing a
mode_indexparameter would allow callers to explore a range of soft modes without rewriting the internals.Proposed behavior
Acceptance criteria
displace_along_soft_modes()returnsnp.ndarray, notlist[np.ndarray]num_childrenparameter is removedmode_index: int = 0parameter is added;0selects the softestmode,
1the second-softest, etc.GBManipulatorValueErroris raised ifmode_indexis out ofrange for the number of soft modes found
test_type_preservation_with_numeric_roundtrippasses without[0]indexing on the resulttest_displace_along_soft_modes_baseandtest_displace_along_soft_modes_with_displacement_thresholdupdated to match the new return type
API / breaking-change impact
num_childrenparameter and changes the return type fromlist[np.ndarray]tonp.ndarray. Any caller usingnum_children > 1or indexing the result with[0]must be updated.Alternatives considered
result[0]for the common single-structure case.num_children— returns a single array whennum_children=1, list otherwise; inconsistent return type makes type hints and callers harder to reason about.squeezeparameter — explicit but adds API surface for a distinction that disappears oncenum_childrenis removed.