-
Notifications
You must be signed in to change notification settings - Fork 842
/
jarvis.py
61 lines (49 loc) · 1.65 KB
/
jarvis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
This module provides conversion between the JARVIS
Atoms object and pymatgen Structure objects.
"""
from pymatgen.core.structure import Structure
try:
from jarvis.core.atoms import Atoms
jarvis_loaded = True
except ImportError:
jarvis_loaded = False
class JarvisAtomsAdaptor:
"""
Adaptor serves as a bridge between JARVIS Atoms and pymatgen objects.
"""
@staticmethod
def get_atoms(structure):
"""
Returns JARVIS Atoms object from pymatgen structure.
Args:
structure: pymatgen.core.structure.Structure
Returns:
JARVIS Atoms object
"""
if not structure.is_ordered:
raise ValueError("JARVIS Atoms only supports ordered structures")
if not jarvis_loaded:
raise ImportError("JarvisAtomsAdaptor requires jarvis-tools package.\n" "Use `pip install -U jarvis-tools`")
elements = [str(site.specie.symbol) for site in structure]
coords = [site.frac_coords for site in structure]
lattice_mat = structure.lattice.matrix
return Atoms(
lattice_mat=lattice_mat,
elements=elements,
coords=coords,
cartesian=False,
)
@staticmethod
def get_structure(atoms):
"""
Returns pymatgen structure from JARVIS Atoms.
Args:
atoms: JARVIS Atoms object
Returns:
Equivalent pymatgen.core.structure.Structure
"""
elements = atoms.elements
coords = atoms.frac_coords
lattice_mat = atoms.lattice_mat
return Structure(lattice_mat, elements, coords, coords_are_cartesian=False)