Skip to content
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

Version 0.1.18: fixes to writeXYZ() #213

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- '1.6'
- '1.7'
- '1.8'
- '1.9'
- '1'
os:
- ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.18]: 2024-02-06

### Changed
- Ambiguity tests exclude `Base.Sort.defalg` on all versions due to a potential false positive.
- `writeXYZ()` methods are simplified and better documented.

### Fixed
- `writeXYZ()` no longer references removed functions from prerelease versions.

## [0.1.17]: 2023-11-29

This is the final feature release in the 0.1 series. All future 0.1 series releases will only
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = [
"Amber Lim <[email protected]>",
"Patrick Cross <[email protected]>"
]
version = "0.1.17"
version = "0.1.18"

[deps]
ComputedFieldTypes = "459fdd68-db75-56b8-8c15-d717a790f88e"
Expand Down
14 changes: 7 additions & 7 deletions src/filetypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ end
readXYZ(filename) = open(readXYZ, filename)

"""
writeXYZ(io::IO, data::AbstractVector{<:AbstractAtomPosition})
writeXYZ(io::IO, data::AbstractAtomList)
writeXYZ(io::IO, data::AbstractCrystal)
writeXYZ(io::IO, data)
writeXYZ(filename, data)

Write an XYZ file based on a set of atomic coordinates.
Write an XYZ file based on a set of atomic coordinate data. This data may be provided in any type
that subtypes `AbstractVector{<:AbstractAtomPosition}`, or types convertible to `AtomList`.
"""
function writeXYZ(io::IO, data::AbstractVector{<:AbstractAtomPosition})
# Write the number of atoms
Expand All @@ -43,13 +43,13 @@ function writeXYZ(io::IO, data::AbstractVector{<:AbstractAtomPosition})
println(io, "File written by Electrum.jl")
# Write lines for all atoms
for atom in data
println(io, atomname(atom), join([lpad(@sprintf("%f", n), 11) for n in coord(atom)]))
println(io, name(atom), join([lpad(@sprintf("%f", n), 11) for n in displacement(atom)]))
end
return nothing
end

writeXYZ(io::IO, data::AbstractAtomList) = writeXYZ(io, coord(cartesian(data)))
writeXYZ(io::IO, data::AbstractCrystal) = writeXYZ(io, atoms(data))
writeXYZ(io::IO, data::AtomList) = writeXYZ(io, data.atoms)
writeXYZ(io::IO, data) = writeXYZ(io, AtomList(data))

function writeXYZ(filename, data)
open(filename; write=true) do io
Expand Down
10 changes: 10 additions & 0 deletions test/filetypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
@test iszero(h - g)
end

@testset "XYZ" begin
xyz_path = joinpath(tmpdir, "test.xyz")
writeXYZ(xyz_path, poscar)
xyz = readXYZ(xyz_path)
list = AtomList(poscar)
@test all(NamedAtom(xyz[n]) == NamedAtom(list[n]) for n in 1:4)
# atol is set to match number of printed digits
@test all(isapprox(displacement(xyz[n]), displacement(list[n]), atol=0.000001) for n in 1:4)
end

@testset "abinit outputs" begin
den = v80_den["density_total"]
wfk = v80_wfk["wavefunction"]
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Test, Aqua, Electrum

tmpdir = mktempdir()

excluded_methods = Function[Base.unsafe_convert, Base.lstrip, Base.rstrip]
excluded_methods = Function[Base.unsafe_convert, Base.lstrip, Base.rstrip, Base.Sort.defalg]
# Base.getindex ambiguity was resolved in 1.9:
# https://github.com/JuliaLang/julia/pull/41807
# TODO: can we still try to test other methods for Base.getindex? It's pretty important...
Expand All @@ -12,9 +12,11 @@ if VERSION < v"1.9"
end
# Base.Sort.defalg ambiguity should be removed in 1.10:
# https://github.com/JuliaLang/julia/pull/47383
#= Aqua.jl seems to think there still is an ambiguity, however:
if VERSION < v"1.10"
push!(excluded_methods, Base.Sort.defalg)
end
=#

Aqua.test_all(Electrum;
ambiguities = (exclude = excluded_methods,)
Expand Down
Loading