Skip to content

Commit

Permalink
Sanitize export extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Liozou committed Jun 15, 2022
1 parent 363317b commit e7b5ff0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export export_vtf, export_cgd

"""
function export_vtf(file, pge::PeriodicGraphEmbedding3D{T}, types=nothing, repeatedges=6, colorname=false, tostring=string, atomnumof==(a,i)->(a isa Integer ? a : i)) where T
function export_vtf(file::AbstractString, pge::PeriodicGraphEmbedding3D{T}, types=nothing, repeatedges=6, colorname=false, tostring=string, atomnumof==(a,i)->(a isa Integer ? a : i)) where T
Export a [`PeriodicGraphEmbedding3D`](@ref) to a .vtf `file` (readable by VMD).
Expand All @@ -10,7 +10,8 @@ to string by the `tostring` function.
The `atomnumof` function takes two arguments `ty` and `i` where `ty` is a type and `i` is
the number of the vertex, and return an `Int` representing an atom number.
"""
function export_vtf(file, pge::PeriodicGraphEmbedding3D{T}, types=nothing, repeatedges=6, colorname=false, tostring=string, atomnumof=(a,i)->(a isa Integer ? a : i)) where T
function export_vtf(file::AbstractString, pge::PeriodicGraphEmbedding3D{T}, types=nothing, repeatedges=6, colorname=false, tostring=string, atomnumof=(a,i)->(a isa Integer ? a : i)) where T
endswith(file, ".vtf") || return export_vtf(file*".vtf", pge, types, repeatedges, colorname, tostring, atomnumof)
mkpath(splitdir(file)[1])
n = nv(pge.g)
open(file, write=true) do f
Expand Down Expand Up @@ -111,6 +112,7 @@ Systre).
If `append` is set, the graph is added at the end of the file.
"""
function export_cgd(file, pge::PeriodicGraphEmbedding, name=basename(splitext(file)[1]), append=false)
endswith(file, ".cgd") || return export_cgd(file*".cgd", pge, name, append)
mkpath(splitdir(file)[1])
open(file; write=true, append) do f
println(f, "CRYSTAL")
Expand Down Expand Up @@ -140,6 +142,7 @@ function export_cgd(file, pge::PeriodicGraphEmbedding, name=basename(splitext(fi
end

function export_cgd(file, g::PeriodicGraph, name=basename(splitext(file)[1]), append=false)
endswith(file, ".cgd") || return export_cgd(file*".cgd", pge, name, append)
mkpath(splitdir(file)[1])
open(file; write=true, append) do f
println(f, "PERIODIC_GRAPH")
Expand Down

0 comments on commit e7b5ff0

Please sign in to comment.