Skip to content

Commit

Permalink
Sniff den_fmt files where END header is on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Mar 5, 2024
1 parent 5ff2481 commit 44d6fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/galaxy/datatypes/test/Fe.den_fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN header

Real Lattice(A) Lattice parameters(A) Cell Angles
2.8335126 0.0000000 0.0000000 a = 2.833513 alpha = 90.000000
0.0000000 2.8335126 0.0000000 b = 2.833513 beta = 90.000000
0.0000000 0.0000000 2.8335126 c = 2.833513 gamma = 90.000000

1 F ! nspins, non-collinear spin
24 24 24 ! fine FFT grid along <a,b,c>
END header: data is "<a b c> charge" in units of electrons/grid_point * number of grid_points

1 1 1 290.606525
20 changes: 12 additions & 8 deletions lib/galaxy/datatypes/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,18 +1394,22 @@ def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
>>> fname = get_test_fname('YbCuAs2.den_fmt')
>>> FormattedDensity().sniff(fname)
True
>>> fname = get_test_fname('Fe.den_fmt')
>>> FormattedDensity().sniff(fname)
True
>>> fname = get_test_fname('Si.param')
>>> FormattedDensity().sniff(fname)
False
"""
begin_header = "BEGIN header"
end_header = 'END header: data is "<a b c> charge" in units of electrons/grid_point * number'
grid_points = "of grid_points"
end_header_spin = 'END header: data is "<a b c> charge spin" in units of electrons/grid_point * nu'
grid_points_spin = "mber of grid_points"
end_header = 'END header: data is "<a b c> charge'
end_header_units = '" in units of electrons/grid_point * number of grid_points'
end_headers = (
f"{end_header}{end_header_units}".replace(" ", ""),
f"{end_header} spin{end_header_units}".replace(" ", ""),
)
handle = file_prefix.string_io()
lines = handle.readlines()
return lines[0].strip() == begin_header and (
(lines[9].strip() == end_header and lines[10].strip() == grid_points)
or (lines[9].strip() == end_header_spin and lines[10].strip() == grid_points_spin)
)
begin_line = lines[0].strip()
end_line = lines[9].strip() + lines[10].strip()
return begin_line == begin_header and end_line.replace(" ", "") in end_headers

0 comments on commit 44d6fe6

Please sign in to comment.