Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for structural data extraction from a JARVIS database entry #139

Merged
merged 6 commits into from
Jan 25, 2024
Merged
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
25 changes: 25 additions & 0 deletions express/parsers/structure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import io
import json

import pymatgen as mg
from pymatgen.core.structure import Structure
from ase.io import read, write
from jarvis.core.atoms import Atoms
from jarvis.io.vasp.inputs import Poscar

from express.parsers import BaseParser
from express.parsers.mixins.ionic import IonicDataMixin
Expand Down Expand Up @@ -33,6 +37,11 @@ def __init__(self, *args, **kwargs):
self.structure_format = "poscar"
self.structure_string = self.espresso_input_to_poscar(self.structure_string)

# convert jarvis-db-entry JSON into poscar
if self.structure_format == "jarvis-db-entry":
self.structure_format = "poscar"
self.structure_string = self.jarvis_db_entry_json_to_poscar(self.structure_string)

# cell_type is either original, primitive or conventional
self.cell_type = kwargs["cell_type"]
self.structure = Structure.from_str(self.structure_string, self.structure_format)
Expand Down Expand Up @@ -223,3 +232,19 @@ def espresso_input_to_poscar(self, espresso_input):
input_.close()
output_.close()
return content

def jarvis_db_entry_json_to_poscar(self, jarvis_db_entry_json_str):
"""
Extracts structure from jarvis atoms dictionary and returns in poscar format.

Args:
jarvis_atoms_json (dict): input content

Returns:
str: poscar
"""
jarvis_db_entry = json.loads(jarvis_db_entry_json_str)
atoms = Atoms.from_dict(jarvis_db_entry["atoms"])
poscar = Poscar(atoms)
content = poscar.to_string()
return content
1 change: 0 additions & 1 deletion express/properties/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from express.parsers.apps.vasp.parser import VaspParser
from express.parsers.crystal import CrystalParser
from express.parsers.molecule import MoleculeParser
from express.parsers.structure import StructureParser # noqa: F401
from express.parsers.utils import lattice_basis_to_poscar
from express.properties import BaseProperty
from express.properties.non_scalar.symmetry import Symmetry
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pymatgen==2023.8.10
ase==3.17.0
esse==2023.12.25.post0
rdkit-pypi>=2022.3.5
jarvis-tools==2023.12.12
4 changes: 2 additions & 2 deletions tests/fixtures/data.py
Git LFS file not shown
92 changes: 92 additions & 0 deletions tests/fixtures/structural/test-002/JVASP-677.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"phi": {
"nelect": 48,
"phi": 4.73414095269429,
"scf_vbm": -1.6519,
"scf_cbm": -1.6472,
"Ef": -1.97822464,
"scf_gap": 0.0,
"avg_max": 2.7559163126942896,
"scf_dir": false
},
"atoms": {
"lattice_mat": [
[
3.353617811446221,
0.0,
0.0
],
[
0.0,
6.273423021773385,
0.0
],
[
0.0,
0.0,
33.313518
]
],
"coords": [
[
0.0,
0.6004615456553349,
0.2002745956304112
],
[
0.5,
0.9651745521229684,
0.205389889617873
],
[
0.0,
0.8600702878546368,
0.2642586539633663
],
[
0.5,
0.3508476059345406,
0.2471701152668883
],
[
0.5,
0.7055702442093444,
0.1414059027438078
],
[
0.0,
0.2147957642231673,
0.1584938427776558
]
],
"elements": [
"Mo",
"Mo",
"Te",
"Te",
"Te",
"Te"
],
"abc": [
3.35362,
6.27342,
33.31352
],
"angles": [
90.0,
90.0,
90.0
],
"cartesian": false,
"props": [
"",
"",
"",
"",
"",
""
]
},
"jid": "JVASP-677",
"doi": "https://figshare.com/articles/dataset/Monolayer_data_for_heterostructure/22344571"
}
14 changes: 10 additions & 4 deletions tests/integration/parsers/test_structure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from express.parsers.structure import StructureParser
from tests.fixtures.data import SI
from tests.fixtures.data import SI, JVASP_677
from tests.integration import IntegrationTestBase


Expand All @@ -26,11 +26,17 @@ def parser(self):
def test_structure_espresso_basis(self):
self.assertDeepAlmostEqual(self.parser.basis(), SI["basis"], places=2)

def test_structure_vasp_basis(self):
self.assertDeepAlmostEqual(self.parser.basis(), SI["basis"], places=2)

def test_structure_espresso_lattice_bravais(self):
self.assertDeepAlmostEqual(self.parser.lattice_bravais(), SI["lattice"], places=2)

def test_structure_vasp_basis(self):
self.assertDeepAlmostEqual(self.parser.basis(), SI["basis"], places=2)

def test_structure_vasp_lattice_bravais(self):
self.assertDeepAlmostEqual(self.parser.lattice_bravais(), SI["lattice"], places=2)

def test_structure_jarvis_db_entry_basis(self):
self.assertDeepAlmostEqual(self.parser.basis(), JVASP_677["basis"], places=2)

def test_structure_jarvis_db_entry_lattice_bravais(self):
self.assertDeepAlmostEqual(self.parser.lattice_bravais(), JVASP_677["lattice"], places=2)
8 changes: 8 additions & 0 deletions tests/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ test_structure_vasp_basis:
test_structure_vasp_lattice_bravais:
structurePath: fixtures/vasp/test-001/POSCAR

test_structure_jarvis_db_entry_basis:
structurePath: fixtures/structural/test-002/JVASP-677.json
structureFormat: jarvis-db-entry

test_structure_jarvis_db_entry_lattice_bravais:
structurePath: fixtures/structural/test-002/JVASP-677.json
structureFormat: jarvis-db-entry

test_molecule_inchi:
structurePath: fixtures/structural/test-001/POSCAR

Expand Down
Loading