Repository navigation
Speed up GRO file reading - #995
Conversation
4b0e8a3 to
fb79bda
Compare
Merging this PR will regress 3 benchmarks
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance ChangesTip Investigate this regression by commenting Comparing Footnotes
|
…g per-atom array assignments
fb79bda to
685fbd5
Compare
GROFile.get_structure()parsed each atom line in a Python loop and assigned every value individually into NumPy arrays (7 scalar__setitem__calls per atom). In addition,_is_int()(used byget_structure()andget_model_count()to find model starts) raised and caught aValueErrorfor every atom line.Fix:
_is_int()returnsFalseearly for lines containing a., whichint()can never parse (all atom and box lines), avoiding exception handling.Results are identical (values and dtypes checked against
main).1aki.gro(1k atoms)get_structure(model=1)1l2y.gro(38 models x 304 atoms)get_structure()1igy.groget_structure(model=1)waterbox.groget_structure(model=1)1aki.groget_model_count()Note: for malformed multi-model files where a later model has a different atom count, a
ValueError(broadcasting) is now raised instead of anIndexError/silently partially filled coordinates.Tests run:
tests/structure/io/test_gro.py.Authored by Claude