-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add PythonCall.jl support by duplicating Python ase interface * Version bump
- Loading branch information
Showing
4 changed files
with
44 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "NQCBase" | ||
uuid = "78c76ebc-5665-4934-b512-82d81b5cbfb7" | ||
authors = ["James Gardner <[email protected]> and contributors"] | ||
version = "0.2.1" | ||
version = "0.2.9" | ||
|
||
[deps] | ||
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" | ||
|
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
using .PythonCall | ||
using Unitful, UnitfulAtomic | ||
|
||
export convert_from_ase_atoms | ||
export convert_to_ase_atoms | ||
|
||
const ase = pyimport("ase") | ||
|
||
convert_to_ase_atoms(atoms::Atoms, R::Matrix) = | ||
ase.Atoms(positions=ustrip.(u"Å", R'u"bohr"), symbols=string.(atoms.types)) | ||
|
||
convert_to_ase_atoms(atoms::Atoms, R::Matrix, ::InfiniteCell) = | ||
convert_to_ase_atoms(atoms, R) | ||
|
||
function convert_to_ase_atoms(atoms::Atoms, R::Matrix, cell::PeriodicCell) | ||
ase.Atoms( | ||
positions=ustrip.(u"Å", R'u"bohr"), | ||
cell=ustrip.(u"Å", cell.vectors'u"bohr"), | ||
symbols=string.(atoms.types), | ||
pbc=cell.periodicity) | ||
end | ||
|
||
function convert_to_ase_atoms(atoms::Atoms, R::Vector{<:Matrix}, cell::AbstractCell) | ||
convert_to_ase_atoms.(Ref(atoms), R, Ref(cell)) | ||
end | ||
|
||
convert_from_ase_atoms(ase_atoms::Py) = | ||
Atoms(ase_atoms), positions(ase_atoms), Cell(ase_atoms) | ||
|
||
Atoms(ase_atoms::Py) = Atoms{Float64}(Symbol.(PyList(ase_atoms.get_chemical_symbols()))) | ||
|
||
positions(ase_atoms::Py) = austrip.(PyArray(ase_atoms.get_positions())'u"Å") | ||
|
||
function Cell(ase_atoms::Py) | ||
if all(PyArray(ase_atoms.cell.array) .== 0) | ||
return InfiniteCell() | ||
else | ||
return PeriodicCell{Float64}(austrip.(PyArray(ase_atoms.cell.array)'u"Å"), [Bool(x) for x in ase_atoms.pbc]) | ||
end | ||
end |