Skip to content

fix: read the cells of extended xyz trajectories - #183

Open
galjos wants to merge 1 commit into
devfrom
fix/extxyz-cells
Open

fix: read the cells of extended xyz trajectories#183
galjos wants to merge 1 commit into
devfrom
fix/extxyz-cells

Conversation

@galjos

@galjos galjos commented Aug 23, 2026

Copy link
Copy Markdown
Member

TrajectoryReader.cells parsed every header line as a PQ xyz header regardless of the trajectory format. An extended xyz header holds only the atom count, so every frame produced a vacuum cell and the box in the Lattice metadata was never read.

reader = TrajectoryReader("traj.extxyz")     # Lattice="10 0 0 0 11 0 0 0 12"
[c.volume for c in reader.read().cells]      # 1320.0
[c.volume for c in reader.cells]             # inf

RDF takes the average volume from cells, so running it on an extended xyz trajectory produced an infinite density and wrote nan and inf into g(r), while the same trajectory read into memory gave correct values.

The cell scan is now format aware and reads each frame own atom count, which also fixes variable size extended xyz files, where the previous code reused the first count and drifted onto atom lines. A format without a cell scanner raises instead of returning vacuum cells.

Present in v1.5.0. 949 tests pass in both type checking modes.

The cell generator behind TrajectoryReader.cells parsed every header
line as a PQ xyz header of the form "n_atoms a b c alpha beta gamma",
regardless of the trajectory format. An extended xyz frame stores the
box as Lattice metadata in the comment line and puts only the atom
count in the header line, so every frame matched the single-field case
and yielded a vacuum cell while the comment line was skipped together
with the atoms. Reading the same file with read() returned the correct
box, so the two entry points disagreed. Any analysis that takes the
cells from the reader instead of from the frames therefore worked with
an infinite volume: an RDF over an extended xyz trajectory produced an
average volume of inf and wrote a column of nan and inf, with an exit
status of zero and nothing but a numpy warning to indicate that the
result was meaningless.

The generator now dispatches on the trajectory format and reads the
Lattice metadata for extended xyz files, carrying the previous cell
over to frames that define no Lattice, exactly as the frame generator
does. A format for which no cell layout is known raises instead of
silently reporting vacuum. The xyz branch also takes the atom count
from the header of each frame rather than from the first line of the
first file, so that a set of files with differing atom counts no
longer runs out of step.
@galjos
galjos requested a review from 97gamjak August 23, 2026 19:36
@github-actions

Copy link
Copy Markdown
Contributor

PYLINT REPORT

Your code has been rated at 9.78/10

Full report

Raw metrics

type number % previous difference
code 15691 45.63 NC NC
docstring 13067 38.00 NC NC
comment 463 1.35 NC NC
empty 5169 15.03 NC NC

Duplication

now previous difference
nb duplicated lines 0 NC NC
percent duplicated lines 0.000 NC NC

Messages by category

type number previous difference
convention 15 NC NC
refactor 135 NC NC
warning 17 NC NC
error 5 NC NC

% errors / warnings by module

module error warning refactor convention
PQAnalysis.type_checking 40.00 0.00 0.00 0.00
PQAnalysis.atomic_system.atomic_system 20.00 11.76 6.67 0.00
PQAnalysis.analysis.vibrational.vibrational_analysis 20.00 0.00 7.41 0.00
PQAnalysis 20.00 0.00 0.00 0.00
PQAnalysis.analysis.vacf._vacf_kernel_py 0.00 11.76 1.48 0.00
PQAnalysis.tools.traj_to_com_traj 0.00 11.76 0.00 0.00
PQAnalysis.io.traj_file._process_lines_py 0.00 11.76 0.00 0.00
PQAnalysis.io.moldescriptor_reader 0.00 11.76 0.00 0.00
PQAnalysis.tools.add_molecule 0.00 5.88 4.44 0.00
PQAnalysis.analysis.rdf._rdf_kernel_py 0.00 5.88 2.22 0.00
PQAnalysis.analysis.msd._msd_kernel_py 0.00 5.88 2.22 0.00
PQAnalysis.io.conversion_api 0.00 5.88 1.48 0.00
PQAnalysis.version 0.00 5.88 0.00 0.00
PQAnalysis.utils.custom_logging 0.00 5.88 0.00 0.00
PQAnalysis.io.write_api 0.00 5.88 0.00 0.00
PQAnalysis.io.restart_file.restart_writer 0.00 0.00 14.81 0.00
PQAnalysis.analysis.rdf.rdf 0.00 0.00 6.67 6.67
PQAnalysis.analysis.msd.msd 0.00 0.00 5.93 33.33
PQAnalysis.io.nep.nep_writer 0.00 0.00 5.19 6.67
PQAnalysis.analysis.vacf.vacf 0.00 0.00 4.44 13.33
PQAnalysis.io.traj_file._slab_parser_py 0.00 0.00 3.70 0.00
PQAnalysis.analysis.vacf.spectrum 0.00 0.00 3.70 0.00
PQAnalysis.io.traj_file.trajectory_reader 0.00 0.00 2.96 0.00
PQAnalysis.topology.bonded_topology.dihedral 0.00 0.00 2.22 0.00
PQAnalysis.core.residue 0.00 0.00 2.22 0.00
PQAnalysis.topology.bonded_topology.bonded_topology 0.00 0.00 1.48 0.00
PQAnalysis.topology.bonded_topology.bond 0.00 0.00 1.48 0.00
PQAnalysis.topology.bonded_topology.angle 0.00 0.00 1.48 0.00
PQAnalysis.io.traj_file.raw_frame_reader 0.00 0.00 1.48 0.00
PQAnalysis.core.cell.cell 0.00 0.00 1.48 0.00
PQAnalysis.atomic_system._standard_properties 0.00 0.00 1.48 0.00
PQAnalysis.analysis.vacf.api 0.00 0.00 1.48 0.00
PQAnalysis.analysis.spectrum_broadening.api 0.00 0.00 1.48 0.00
PQAnalysis.analysis.momentum.api 0.00 0.00 1.48 0.00
PQAnalysis.analysis.vibrational.vibrational_input_file_reader 0.00 0.00 0.74 6.67
PQAnalysis.traj.formats 0.00 0.00 0.74 0.00
PQAnalysis.topology.topology 0.00 0.00 0.74 0.00
PQAnalysis.topology.selection 0.00 0.00 0.74 0.00
PQAnalysis.io.traj_file.frame_reader 0.00 0.00 0.74 0.00
PQAnalysis.io.restart_file.restart_reader 0.00 0.00 0.74 0.00
PQAnalysis.io.input_file_reader.pq_analysis._parse 0.00 0.00 0.74 0.00
PQAnalysis.io.input_file_reader.pq.pq_input_file_reader 0.00 0.00 0.74 0.00
PQAnalysis.io.input_file_reader.input_file_parser 0.00 0.00 0.74 0.00
PQAnalysis.io.info_file_reader 0.00 0.00 0.74 0.00
PQAnalysis.io.formats 0.00 0.00 0.74 0.00
PQAnalysis.analysis.momentum.momentum 0.00 0.00 0.74 0.00
PQAnalysis.core.atom.element 0.00 0.00 0.00 13.33
PQAnalysis.analysis.vacf.vacf_input_file_reader 0.00 0.00 0.00 6.67
PQAnalysis.analysis.rdf.rdf_input_file_reader 0.00 0.00 0.00 6.67
PQAnalysis.analysis.msd.msd_input_file_reader 0.00 0.00 0.00 6.67

Messages

message id occurrences
too-many-positional-arguments 29
too-many-arguments 29
duplicate-code 20
too-many-locals 15
too-many-instance-attributes 13
invalid-name 12
too-complex 9
inconsistent-return-statements 8
fixme 7
too-many-branches 5
missing-type-doc 4
too-many-return-statements 3
too-many-lines 3
unused-import 2
too-many-statements 2
redefined-builtin 2
missing-kwoa 2
use-set-for-membership 1
unexpected-keyword-arg 1
too-many-public-methods 1
possibly-used-before-assignment 1
no-member 1
missing-param-doc 1
arguments-differ 1

@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.92%. Comparing base (bd55571) to head (4c02f93).
⚠️ Report is 8 commits behind head on dev.

Files with missing lines Patch % Lines
PQAnalysis/io/traj_file/trajectory_reader.py 89.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #183      +/-   ##
==========================================
+ Coverage   93.86%   93.92%   +0.05%     
==========================================
  Files         177      177              
  Lines        9215     9254      +39     
==========================================
+ Hits         8650     8692      +42     
+ Misses        565      562       -3     
Flag Coverage Δ
unittests 93.92% <90.32%> (+0.05%) ⬆️
Files with missing lines Coverage Δ
PQAnalysis/io/traj_file/frame_reader.py 100.00% <100.00%> (ø)
PQAnalysis/io/traj_file/trajectory_reader.py 98.66% <89.65%> (-1.34%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant