Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NQCDInterfASE"
uuid = "4606675f-2246-4a0b-99d5-75b910de637b"
authors = ["Alexander Spears <alexander.spears@warwick.ac.uk> and contributors"]
version = "1.0.2"
version = "1.0.3"

[deps]
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
Expand All @@ -13,7 +13,7 @@ UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"

[compat]
CondaPkg = "0.2.29"
NQCBase = "0.5, 1"
NQCBase = "1.1"
NQCModels = "0.10, 1"
PythonCall = "0.9"
Unitful = "1.22"
Expand Down
11 changes: 9 additions & 2 deletions src/NQCDInterfASE.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module NQCDInterfASE

using PythonCall
using NQCBase: Atoms, AbstractCell, PeriodicCell, InfiniteCell
using NQCBase: Atoms, AbstractCell, PeriodicCell, InfiniteCell, Structure
import NQCModels
using Unitful, UnitfulAtomic

Expand Down Expand Up @@ -29,9 +29,16 @@ end
function convert_to_ase_atoms(atoms::Atoms, R::Vector{<:Matrix}, cell::AbstractCell)
convert_to_ase_atoms.(Ref(atoms), R, Ref(cell))
end
# Missing conversion of info to atoms["info"] because of type conversion for arbitrary types.
convert_to_ase_atoms(st::Structure) = convert_to_ase_atoms(st.atoms, st.positions, st.cell)

convert_from_ase_atoms(ase_atoms::PythonCall.Py) =
Atoms(ase_atoms), positions(ase_atoms), Cell(ase_atoms)
Structure(
Atoms(ase_atoms),
positions(ase_atoms),
Cell(ase_atoms),
PythonCall.pyconvert(Dict{String, Any}, ase_atoms["info"]) # Hopefully this conversion covers anything you might drop into the info.
)

Atoms(ase_atoms::PythonCall.Py) = Atoms{Float64}(Symbol.(PythonCall.PyList(ase_atoms.get_chemical_symbols())))

Expand Down
23 changes: 16 additions & 7 deletions test/ase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ using PythonCall
R = rand(3, 4) .* 10

ase_atoms = convert_to_ase_atoms(atoms, R, cell)
new_atoms, new_R, new_cell = convert_from_ase_atoms(ase_atoms)
nqcd_structure = convert_from_ase_atoms(ase_atoms)

@test new_atoms == atoms
@test new_cell.vectors ≈ cell.vectors
@test new_cell.inverse ≈ cell.inverse
@test new_cell.periodicity ≈ cell.periodicity
@test new_R ≈ R
@test nqcd_structure.atoms == atoms
@test nqcd_structure.cell.vectors ≈ cell.vectors
@test nqcd_structure.cell.inverse ≈ cell.inverse
@test nqcd_structure.cell.periodicity ≈ cell.periodicity
@test nqcd_structure.positions ≈ R
end

@testset "Multiple frames" begin
Expand All @@ -25,5 +25,14 @@ end

ase_atoms = convert_to_ase_atoms(atoms, R, cell)
out = convert_from_ase_atoms.(ase_atoms)
@test out isa Vector{<:Tuple}
# Correct types
@test out isa Vector{<:NQCBase.Structure}
for frame in structure
nqcd_structure = frame
@test nqcd_structure.atoms == atoms
@test nqcd_structure.cell.vectors ≈ cell.vectors
@test nqcd_structure.cell.inverse ≈ cell.inverse
@test nqcd_structure.cell.periodicity ≈ cell.periodicity
@test nqcd_structure.positions ≈ R
end
end
Loading