Skip to content

Commit

Permalink
add quiet flag to write_cssr (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
eahenle authored Jun 14, 2022
1 parent d6546f1 commit 2d40642
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Xtals"
uuid = "ede5f01d-793e-4c47-9885-c447d1f18d6d"
authors = ["SimonEnsemble <cory.simon@oregonstate.edu>"]
version = "0.4.3"
version = "0.4.4"

[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand Down
29 changes: 16 additions & 13 deletions src/crystal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -907,28 +907,31 @@ write crystal structure to `.cssr` format.
# arguments
* `xtal::Crystal`: crystal to write to file
* `filename::String`: filename to write to. default is to write `.cssr` file to `pwd()`. will append `.cssr` if absent from `filename`.
* `quiet::Bool` : (optional) set `true` to suppress console output
"""
function write_cssr(xtal::Crystal, filename::String)
function write_cssr(xtal::Crystal, filename::String; quiet::Bool=false)
@assert xtal.symmetry.is_p1 "crystal must be in P1 symmetry"
if ! occursin(".cssr", filename)
filename *= ".cssr"
end
f = open(filename, "w")
@printf(f, "%f %f %f\n", xtal.box.a, xtal.box.b, xtal.box.c)
@printf(f, "%f %f %f SPGR = 1 P 1 OPT = 1\n", rad2deg(xtal.box.α), rad2deg(xtal.box.β), rad2deg(xtal.box.γ))
@printf(f, "%d 0\n0 xtal : xtal", xtal.atoms.n)
for a = 1:xtal.atoms.n
q = 0.0
if xtal.charges.n != 0
q = xtal.charges.q[a]
open(filename, "w") do f
@printf(f, "%f %f %f\n", xtal.box.a, xtal.box.b, xtal.box.c)
@printf(f, "%f %f %f SPGR = 1 P 1 OPT = 1\n", rad2deg(xtal.box.α), rad2deg(xtal.box.β), rad2deg(xtal.box.γ))
@printf(f, "%d 0\n0 xtal : xtal", xtal.atoms.n)
for a = 1:xtal.atoms.n
q = 0.0
if xtal.charges.n != 0
q = xtal.charges.q[a]
end
@printf(f, "\n%d %s %f %f %f 0 0 0 0 0 0 0 0 %f", a, xtal.atoms.species[a], xtal.atoms.coords.xf[:, a]..., q, )
end
@printf(f, "\n%d %s %f %f %f 0 0 0 0 0 0 0 0 %f", a, xtal.atoms.species[a], xtal.atoms.coords.xf[:, a]..., q, )
end
close(f)
@info "see $filename"
if !quiet
@info "see $filename"
end
end

write_cssr(crystal::Crystal) = write_cssr(crystal, String(split(crystal.name, ".")[1]))
write_cssr(crystal::Crystal; kwargs...) = write_cssr(crystal, String(split(crystal.name, ".")[1]))


"""
Expand Down
2 changes: 1 addition & 1 deletion test/crystal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ end

da_xtalname = "ATIBOU01_clean"
xtal_cif = Crystal(da_xtalname * ".cif", include_zero_charges=true)
write_cssr(xtal_cif)
write_cssr(xtal_cif, quiet=true)
write_cssr(xtal_cif, joinpath(rc[:paths][:crystals], da_xtalname * ".cssr"))
xtal_cssr = Crystal(da_xtalname * ".cssr", include_zero_charges=true)
@test isapprox(xtal_cssr, xtal_cif, atol=0.0001)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
testfiles = [
"crystal.jl",
"bonds.jl",
"misc.jl",
"crystal.jl",
"matter.jl",
"distance.jl",
"box.jl",
Expand Down

0 comments on commit 2d40642

Please sign in to comment.