-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,55 @@ | ||
import XCrySDenStructureFormat as XSF | ||
|
||
""" | ||
Parse or write file using [XSF](https://github.com/azadoks/XCrySDenStructureFormat.jl) | ||
Parse or write file using [XCrySDenStructureFormat](https://github.com/azadoks/XCrySDenStructureFormat.jl). | ||
Supported formats: | ||
- [XSF](http://www.xcrysden.org/doc/XSF.html) | ||
- [XSF](http://www.xcrysden.org/doc/XSF.html) and [AXSF](XCrySDenStructureFormat) | ||
atomic structure files. These are the files typically used by the | ||
[XCrySDen](http://www.xcrysden.org/) visualisation program. | ||
""" | ||
struct XsfParser <: AbstractParser end | ||
struct XcrysdenstructureformatParser <: AbstractParser end | ||
|
||
function supports_parsing(::XsfParser, file; save, trajectory) | ||
function supports_parsing(::XcrysdenstructureformatParser, file; save, trajectory) | ||
_, ext = splitext(file) | ||
ext in (".xsf", ".axsf") | ||
end | ||
|
||
function load_system(::XsfParser, file::AbstractString, index=nothing) | ||
if isnothing(index) | ||
frames = XSF.load_xsf(file) | ||
function load_system(::XcrysdenstructureformatParser, file::AbstractString, index=nothing) | ||
if !isnothing(index) | ||
return XSF.load_xsf(file)[index] | ||
end | ||
|
||
|
||
frames = XSF.load_xsf(file) | ||
if !(frames isa AbstractVector) | ||
# load_xsf Returns plain structure in case only a single structure in the file | ||
return frames | ||
else | ||
isempty(frames) && error( | ||
"XSF returned no frames. Check the passed file is a valid (a)xsf file." | ||
) | ||
return last(frames) | ||
else | ||
return XSF.load_xsf(file)[index] | ||
end | ||
end | ||
|
||
function save_system(::XsfParser, file::AbstractString, system::AbstractSystem) | ||
function save_system(::XcrysdenstructureformatParser, | ||
file::AbstractString, system::AbstractSystem) | ||
XSF.save_xsf(file, system) | ||
end | ||
|
||
function load_trajectory(::XsfParser, file::AbstractString) | ||
XSF.load_xsf(file) | ||
end | ||
|
||
function save_system(::XsfParser, file::AbstractString, system::AbstractSystem) | ||
XSF.save_xsf(file, system) | ||
function load_trajectory(::XcrysdenstructureformatParser, file::AbstractString) | ||
# load_xsf Returns plain structure in case only a single structure in the file, | ||
# so we need to re-wrap to keep a consistent interface. | ||
ret = XSF.load_xsf(file) | ||
if !(ret isa AbstractVector) | ||
return [ret] | ||
else | ||
return ret | ||
end | ||
end | ||
|
||
function save_trajectory(::XsfParser, file::AbstractString, | ||
function save_trajectory(::XcrysdenstructureformatParser, file::AbstractString, | ||
systems::AbstractVector{<:AbstractSystem}) | ||
XSF.save_xsf(file, systems) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters