-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
91 additions
and
26 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
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
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
This file was deleted.
Oops, something went wrong.
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
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,50 @@ | ||
from __future__ import annotations | ||
|
||
try: | ||
import ase | ||
from pymatgen.core import Element, Structure | ||
except ImportError: | ||
raise ImportError("Try installing dependencies with `pip install moyopy[interface]`") | ||
|
||
import moyopy | ||
|
||
|
||
class MoyoAdapter: | ||
@staticmethod | ||
def get_structure(cell: moyopy.Cell) -> Structure: | ||
species = [Element.from_Z(number) for number in cell.numbers] | ||
return Structure(lattice=cell.basis, species=species, coords=cell.positions) | ||
|
||
@staticmethod | ||
def get_atoms(cell: moyopy.Cell) -> ase.Atoms: | ||
atoms = ase.Atoms( | ||
cell=cell.basis, | ||
scaled_positions=cell.positions, | ||
numbers=cell.numbers, | ||
pbc=True, | ||
) | ||
return atoms | ||
|
||
@staticmethod | ||
def from_structure(structure: Structure) -> moyopy.Cell: | ||
basis = structure.lattice.matrix | ||
positions = structure.frac_coords | ||
numbers = [site.specie.Z for site in structure] | ||
|
||
return moyopy.Cell( | ||
basis=basis.tolist(), | ||
positions=positions.tolist(), | ||
numbers=numbers, | ||
) | ||
|
||
@staticmethod | ||
def from_atoms(atoms: ase.Atoms) -> moyopy.Cell: | ||
basis = list(atoms.cell) | ||
positions = atoms.get_scaled_positions() | ||
numbers = atoms.get_atomic_numbers() | ||
|
||
return moyopy.Cell( | ||
basis=basis, | ||
positions=positions, | ||
numbers=numbers, | ||
) |
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
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,22 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
|
||
import moyopy | ||
from moyopy.interface import MoyoAdapter | ||
|
||
|
||
def test_pymatgen_moyopy(wurtzite: moyopy.Cell): | ||
structure = MoyoAdapter.get_structure(wurtzite) | ||
cell = MoyoAdapter.from_structure(structure) | ||
assert np.allclose(cell.basis, wurtzite.basis) | ||
assert np.allclose(cell.positions, wurtzite.positions) | ||
assert cell.numbers == wurtzite.numbers | ||
|
||
|
||
def test_ase_moyopy(wurtzite: moyopy.Cell): | ||
atoms = MoyoAdapter.get_atoms(wurtzite) | ||
cell = MoyoAdapter.from_atoms(atoms) | ||
assert np.allclose(cell.basis, wurtzite.basis) | ||
assert np.allclose(cell.positions, wurtzite.positions) | ||
assert cell.numbers == wurtzite.numbers |