-
Notifications
You must be signed in to change notification settings - Fork 5
Fix triclinic cell at 0,0,0 #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughModify _vector_to_lammps to treat zero-valued vectors as valid input (check now uses Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant ASEWrapper as ASE Wrapper
participant _Vec as _vector_to_lammps
participant Prism
participant LAMMPS as LAMMPS Engine
Caller->>ASEWrapper: interactive_structure_setter(structure, ...)
ASEWrapper->>_Vec: _vector_to_lammps(vector, prism)
alt vector is None
_Vec->>ASEWrapper: return None
else vector is not None (including zeros)
_Vec->>Prism: apply prism conversion (if provided)
Prism-->>_Vec: transformed vector
_Vec->>_Vec: flatten() -> 1D array
_Vec-->>ASEWrapper: return flattened vector
end
ASEWrapper->>LAMMPS: create_atoms(pos_vec_or_none, ...)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #368 +/- ##
==========================================
+ Coverage 81.93% 82.31% +0.37%
==========================================
Files 5 5
Lines 559 554 -5
==========================================
- Hits 458 456 -2
+ Misses 101 98 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
pylammpsmpi/wrapper/ase.py (3)
480-487
: np.any(vector) drops legitimate all-zero data; make “None” mean “unset” onlycurrent behavior: all-zero arrays are treated as “absent” and collapsed to None. That’s why you needed a special fallback for positions. A simpler, more predictable rule: only treat vector is None as unset, otherwise transform+flatten regardless of values. This also preserves intentional zero velocities rather than silently omitting them.
Proposed patch:
def _vector_to_lammps(vector, prism): - if vector is not None and np.any(vector): - if not _check_ortho_prism(prism=prism): - vector = prism.vector_to_lammps(vector) - return vector.flatten() - else: - return None + if vector is None: + return None + if not _check_ortho_prism(prism=prism): + vector = prism.vector_to_lammps(vector) + return np.asarray(vector).flatten()This change would also make the new positions fallback unnecessary in most cases, but keeping the defensive fallback is fine.
291-296
: Incorrect exception type and broken “missing elements” messageget_lammps_indicies_from_ase_structure will raise a ValueError (not KeyError) if an element in the structure is not mapped; and the current message uses el_dict (always empty here) and expects an Abbreviation attribute on strings. Fix both.
- except KeyError: - missing = set(get_species_symbols(structure)).difference(el_dict.keys()) - missing = ", ".join([el.Abbreviation for el in missing]) + except ValueError: + present = set(get_species_symbols(structure)) + allowed = set(el_eam_lst) + missing = ", ".join(sorted(present - allowed)) raise ValueError( - f"Structure contains elements [{missing}], that are not present in the potential!" + f"Structure contains elements [{missing}] that are not present in the potential!" )
142-145
: Typos in warning text (“upper trangular”)Minor wording fix improves clarity and searchability of logs.
- "Warning: setting upper trangular matrix might slow down the calculation", + "Warning: setting an upper triangular matrix might slow down the calculation",Also applies to: 221-225
tests/test_ase_interface.py (1)
480-489
: Expanded structure set and expected energies look consistent; consider naming and coverage tweaks
- The added bulk_al_small = bulk("Al").repeat([2, 2, 2]) is a nice addition to exercise the triclinic/default cell path; LGTM overall.
- Minor naming nit: bulk_al_small doesn’t convey why it’s added; bulk_al_skewed or bulk_al_default would be clearer.
- To fully cover the new positions fallback (and the mirrored fix I suggested), add a test where positions are explicitly set to all zeros to ensure no crash and correct propagation.
Sketch for an extra test:
def test_set_all_zero_positions(self): lmp = LammpsASELibrary(working_directory=None, cores=1, comm=None, logger=logging.getLogger("ZeroPosLogger"), log_file=None, library=LammpsLibrary(cores=2), disable_log_file=True) structure = bulk("Al", cubic=True) lmp.interactive_structure_setter( structure=structure, units="lj", dimension=3, boundary=" ".join(["p" if c else "f" for c in structure.pbc]), atom_style="atomic", el_eam_lst=["Al"], calc_md=False ) zeros = np.zeros_like(structure.positions) lmp.interactive_positions_setter(positions=zeros) lmp.interactive_lib_command("run 0") self.assertTrue(np.allclose(lmp.interactive_positions_getter(), zeros))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
pylammpsmpi/wrapper/ase.py
(1 hunks)tests/test_ase_interface.py
(1 hunks)
Could you say what was the problem? |
Für |
Summary by CodeRabbit
Bug Fixes
Tests