-
Notifications
You must be signed in to change notification settings - Fork 158
fix(dftbplus): parse all atoms instead of truncating to 4 #1037
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| SCC converged | ||
|
|
||
| Total Forces | ||
| 1 0.010000000000 0.002000000000 0.003000000000 | ||
| 2 -0.015000000000 0.001000000000 0.002000000000 | ||
| 3 0.005000000000 -0.008000000000 0.001000000000 | ||
| 4 0.003000000000 0.004000000000 -0.006000000000 | ||
| 5 -0.002000000000 0.003000000000 0.005000000000 | ||
| 6 0.001000000000 -0.001000000000 -0.002000000000 | ||
|
|
||
| Total energy: -12.3456789012 H -335.9999 eV |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Geometry = GenFormat { | ||
| 6 C | ||
| C H O N S Cl | ||
| 1 1 1.000000 0.000000 0.000000 | ||
| 2 2 1.500000 0.000000 0.000000 | ||
| 3 3 2.000000 1.000000 0.000000 | ||
| 4 4 2.500000 0.000000 1.000000 | ||
| 5 5 3.000000 1.000000 1.000000 | ||
| 6 6 3.500000 0.500000 0.500000 | ||
| } | ||
| Driver = {} | ||
| Hamiltonian = DFTB { | ||
| SCC = Yes | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||||||||||||||||||||||||
| """Test that DFTB+ parser handles systems with more than 4 atoms.""" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Add parent directory to path for imports | ||||||||||||||||||||||||||||
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||||||||||||||||||||||||||||
| from dpdata.formats.dftbplus.output import read_dftb_plus | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class TestDftbPlusSixAtoms(unittest.TestCase): | ||||||||||||||||||||||||||||
| """Test DFTB+ parser with a 6-atom system (beyond the original 4-atom limit).""" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def test_six_atoms_parsed_correctly(self): | ||||||||||||||||||||||||||||
| """Verify that all 6 atoms are parsed, not truncated to 4.""" | ||||||||||||||||||||||||||||
| symbols, coord, energy, forces = read_dftb_plus( | ||||||||||||||||||||||||||||
| "dftbplus/dftb_pin_6atoms.hsd", | ||||||||||||||||||||||||||||
| "dftbplus/detailed_6atoms.out", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Use robust path construction for test data files. Hardcoded relative paths like 🛠️ Proposed fix def test_six_atoms_parsed_correctly(self):
"""Verify that all 6 atoms are parsed, not truncated to 4."""
+ base_dir = os.path.dirname(os.path.abspath(__file__))
symbols, coord, energy, forces = read_dftb_plus(
- "dftbplus/dftb_pin_6atoms.hsd",
- "dftbplus/detailed_6atoms.out",
+ os.path.join(base_dir, "dftbplus", "dftb_pin_6atoms.hsd"),
+ os.path.join(base_dir, "dftbplus", "detailed_6atoms.out"),
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Should have 6 atoms, not 4 | ||||||||||||||||||||||||||||
| self.assertEqual(len(symbols), 6) | ||||||||||||||||||||||||||||
| self.assertEqual(coord.shape, (6, 3)) | ||||||||||||||||||||||||||||
| self.assertEqual(forces.shape, (6, 3)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check atom symbols | ||||||||||||||||||||||||||||
| expected_symbols = ["C", "H", "O", "N", "S", "Cl"] | ||||||||||||||||||||||||||||
| np.testing.assert_array_equal(symbols, expected_symbols) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check coordinates | ||||||||||||||||||||||||||||
| expected_coord = np.array( | ||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||
| [1.0, 0.0, 0.0], | ||||||||||||||||||||||||||||
| [1.5, 0.0, 0.0], | ||||||||||||||||||||||||||||
| [2.0, 1.0, 0.0], | ||||||||||||||||||||||||||||
| [2.5, 0.0, 1.0], | ||||||||||||||||||||||||||||
| [3.0, 1.0, 1.0], | ||||||||||||||||||||||||||||
| [3.5, 0.5, 0.5], | ||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| np.testing.assert_array_almost_equal(coord, expected_coord) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check forces | ||||||||||||||||||||||||||||
| expected_forces = np.array( | ||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||
| [0.01, 0.002, 0.003], | ||||||||||||||||||||||||||||
| [-0.015, 0.001, 0.002], | ||||||||||||||||||||||||||||
| [0.005, -0.008, 0.001], | ||||||||||||||||||||||||||||
| [0.003, 0.004, -0.006], | ||||||||||||||||||||||||||||
| [-0.002, 0.003, 0.005], | ||||||||||||||||||||||||||||
| [0.001, -0.001, -0.002], | ||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| np.testing.assert_array_almost_equal(forces, expected_forces) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check energy | ||||||||||||||||||||||||||||
| self.assertAlmostEqual(energy, -12.3456789012) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||
| unittest.main() | ||||||||||||||||||||||||||||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix
sys.pathinsertion to correctly point to the parent directory.The comment states
# Add parent directory to path, butos.path.dirname(os.path.abspath(__file__))points to thetestsdirectory, not its parent. If the project root needs to be added tosys.pathfor manual test execution, it should traverse one level higher.Alternatively, if you run your tests exclusively via a runner like
pytestfrom the root directory, this path manipulation can be removed entirely.🛠️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents