Skip to content

Commit

Permalink
Issues with ExtXYZ fixed (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Oct 4, 2023
1 parent f15cec6 commit 59e6b8c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AtomsIO"
uuid = "1692102d-eeb4-4df9-807b-c9517f998d44"
authors = ["Michael F. Herbst <info@michael-herbst.com> and contributors"]
version = "0.2.2"
version = "0.2.3"

[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
Expand All @@ -18,7 +18,7 @@ XCrySDenStructureFormat = "02310045-4665-40c9-a658-98c497d2eca9"
AtomsBase = "0.3"
AtomsBaseTesting = "0.1"
Chemfiles = "0.10.41"
ExtXYZ = "0.1.11"
ExtXYZ = "0.1.14"
PeriodicTable = "1"
Reexport = "1"
Unitful = "1"
Expand Down
2 changes: 0 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ DocMeta.setdocmeta!(AtomsIO, :DocTestSetup, :(using AtomsIO, AtomsIOPython); rec
makedocs(;
modules=[AtomsIO, AtomsIOPython],
authors="Michael F. Herbst <info@michael-herbst.com> and contributors",
repo="https://github.com/mfherbst/AtomsIO.jl/blob/{commit}{path}#{line}",
sitename="AtomsIO",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
Expand All @@ -30,7 +29,6 @@ makedocs(;
"file_formats.md",
],
checkdocs=:exports,
strict=true
)

deploydocs(;
Expand Down
30 changes: 24 additions & 6 deletions src/extxyz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,33 @@ function supports_parsing(::ExtxyzParser, file; save, trajectory)
ext in (".xyz", ".extxyz")
end


function _extxyz_read_frames(args...; kwargs...)
frames = nothing
try
frames = ExtXYZ.read_frames(args...; kwargs...)
catch e
# Version branch is needed because current_exceptions only
# appeared in 1.7
if VERSION v"1.7" && e isa TaskFailedException
cur_e = last(current_exceptions(e.task))
rethrow(cur_e.exception)
else
rethrow()
end
end
if isnothing(frames) || isempty(frames)
error("ExtXYZ returned no frames. Check the passed file is a valid (ext)xyz file.")
end
frames
end

function load_system(::ExtxyzParser, file::AbstractString, index=nothing)
if isnothing(index)
frames = ExtXYZ.read_frames(file)
isempty(frames) && error(
"ExtXYZ returned no frames. Check the passed file is a valid (ext)xyz file."
)
frames = _extxyz_read_frames(file)
return ExtXYZ.Atoms(last(frames))
else
frame = only(ExtXYZ.read_frames(file, index))
frame = only(_extxyz_read_frames(file, index))
return ExtXYZ.Atoms(frame)
end
end
Expand All @@ -31,7 +49,7 @@ function save_system(::ExtxyzParser, file::AbstractString, system::AbstractSyste
end

function load_trajectory(::ExtxyzParser, file::AbstractString)
ExtXYZ.Atoms.(ExtXYZ.read_frames(file))
ExtXYZ.Atoms.(_extxyz_read_frames(file))
end

function save_trajectory(::ExtxyzParser, file::AbstractString,
Expand Down
2 changes: 1 addition & 1 deletion src/xsf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCrySDenStructureFormat as XSF
Parse or write file using [XCrySDenStructureFormat](https://github.com/azadoks/XCrySDenStructureFormat.jl).
Supported formats:
- [XSF](http://www.xcrysden.org/doc/XSF.html) and [AXSF](XCrySDenStructureFormat)
- [XSF](http://www.xcrysden.org/doc/XSF.html) and [AXSF](http://www.xcrysden.org/doc/XSF.html)
atomic structure files. These are the files typically used by the
[XCrySDen](http://www.xcrysden.org/) visualisation program.
"""
Expand Down
10 changes: 10 additions & 0 deletions test/failed_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ using LinearAlgebra
end
end

@testset "Zero atoms in XYZ" begin
@static if VERSION < v"1.7"
@test_throws TaskFailedException load_system("files/zero_atoms.xyz")
elseif VERSION < v"1.8"
@test_throws ErrorException load_system("files/zero_atoms.xyz")
else
@test_throws "ExtXYZ frame contains zero atoms." load_system("files/zero_atoms.xyz")
end
end

@testset "XYZ from Lammps" begin
@static if VERSION < v"1.8"
@test_throws ErrorException load_system("files/lammps.xyz")
Expand Down
3 changes: 3 additions & 0 deletions test/files/zero_atoms.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0


2 comments on commit 59e6b8c

@mfherbst
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92720

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" 59e6b8c61f525fda8a243474700cc4854dd8a93d
git push origin v0.2.3

Please sign in to comment.