Skip to content

Commit

Permalink
Fix bug in parse_as_chemfile, types need to be reversed (#19)
Browse files Browse the repository at this point in the history
* Fix bug in `parse_as_chemfile`, `types` need to be reversed

* Add Non-CIF tests and fix an UndefVarError in error string
  • Loading branch information
rashidrafeek authored Nov 21, 2023
1 parent bcdd0aa commit 6fb53b3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ function sanitize_removeatoms!(graph::PeriodicGraph3D, pos, types, mat, options)
typu = types[u.v]
if typu === :C
u.v toremove && continue
Float64(norm(mat * (pos[u.v] .+ u.ofs .- pos[i]))) > 1.45 && continue
bondlength = Float64(norm(mat * (pos[u.v] .+ u.ofs .- pos[i])))
bondlength > 1.45 && continue
@ifwarn if isempty(toremove)
@warn lazy"C suspiciously close to a metal (bond length: $bondlength) will be removed."
end
Expand Down Expand Up @@ -1110,6 +1111,7 @@ function parse_as_chemfile(frame::Chemfiles.Frame, options::Options, name::Strin
push!(types, typ)
end
end
reverse!(types)

_pos = collect(eachcol(Chemfiles.positions(frame)))
cell = cell_with_warning(SMatrix{3,3,BigFloat,9}(Chemfiles.matrix(Chemfiles.UnitCell(frame)))')
Expand Down
38 changes: 38 additions & 0 deletions test/Moganite.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
36
Lattice="8.7371 0.0 0.0 0.0 4.8692 0.0 -0.036115822218046476 0.0 10.721639172131542" Properties=species:S:1:pos:R:3 pbc="T T T"
Si 2.18427500 4.73578392 0.00000000
Si 6.53476709 2.30118392 5.36081959
Si 6.55282500 0.13341608 0.00000000
Si 2.16621709 2.56801608 5.36081959
Si 0.08391745 1.21048312 1.80337971
Si 4.43440954 3.64508312 7.16419929
Si 4.24851673 1.21048312 8.91825946
Si 8.63512464 3.64508312 3.55743988
Si 4.45246745 3.65871688 1.80337971
Si 0.06585954 1.22411688 7.16419929
Si 8.61706673 3.65871688 8.91825946
Si 4.26657464 1.22411688 3.55743988
O 8.53536338 0.31357648 3.08568775
O 4.14875547 2.74817648 8.44650734
O 4.53417080 0.31357648 7.63595142
O 0.18367871 2.74817648 2.27513183
O 4.16681338 4.55562352 3.08568775
O 8.51730547 2.12102352 8.44650734
O 0.16562080 4.55562352 7.63595142
O 4.55222871 2.12102352 2.27513183
O 1.46246657 0.83165936 1.07430825
O 5.81295866 3.26625936 6.43512783
O 2.86996760 0.83165936 9.64733093
O 7.25657551 3.26625936 4.28651134
O 5.83101657 4.03754064 1.07430825
O 1.44440866 1.60294064 6.43512783
O 7.23851760 4.03754064 9.64733093
O 2.88802551 1.60294064 4.28651134
O 7.60146031 1.11796832 0.72371064
O 3.21485240 3.55256832 6.08453023
O 5.46807387 1.11796832 9.99792853
O 1.11758178 3.55256832 4.63710894
O 3.23291031 3.75123168 0.72371064
O 7.58340240 1.31663168 6.08453023
O 1.09952387 3.75123168 9.99792853
O 5.48613178 1.31663168 4.63710894
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,11 @@ end
Test.get_testset().n_passed += length(unstabletry) - failures
@test failures == 0
end

@testset "Non-CIF Files" begin
testcase = joinpath(last(_finddirs()), "test", "Moganite.xyz")
mogtopo = extract1(determine_topology(testcase))
@test string(mogtopo) == "mog"
# Test ordering of species is correct while parsing with chemfiles
@test parse_chemfile(testcase).types == [repeat([:Si], 12); repeat([:O], 24)]
end

0 comments on commit 6fb53b3

Please sign in to comment.