Commit a683a4e3 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added possibility of creating a parsed template from an ase.Atoms directly,...

Added possibility of creating a parsed template from an ase.Atoms directly, added test for 2D material detection (graphene).
parent f0a8f8ac
Pipeline #67315 passed with stages
in 13 minutes and 23 seconds
{
"section_run": [
{
"_name": "section_run",
"_gIndex": 0,
"program_name": "VASP",
"program_version": "4.6.35 3Apr08 complex parallel LinuxIFC",
"program_basis_set_type": "plane waves",
"section_method": [
{
"_name": "section_method",
"_gIndex": 0,
"electronic_structure_method": "DFT",
"section_XC_functionals": [
{
"_name": "section_XC_functionals",
"_gIndex": 0,
"XC_functional_name": "GGA_X_PBE"
}
]
}
],
"section_single_configuration_calculation": [
{
"_name": "section_single_configuration_calculation",
"_gIndex": 0,
"single_configuration_calculation_to_system_ref": 0,
"single_configuration_to_calculation_method_ref": 0,
"energy_free": -1.5936767191492225e-18,
"energy_total": -1.5935696296699573e-18,
"energy_total_T0": -3.2126683561907e-22
}
],
"section_sampling_method": [
{
"_name": "section_sampling_method",
"_gIndex": 0,
"sampling_method": "geometry_optimization"
}
],
"section_frame_sequence": [
{
"_name": "section_frame_sequence",
"_gIndex": 0,
"frame_sequence_to_sampling_ref": 0,
"frame_sequence_local_frames_ref": [
0
]
}
]
}
]
}
......@@ -14,6 +14,8 @@
import pytest
from ase import Atoms
from nomad.parsing import LocalBackend
from nomad.normalizing import normalizers
......@@ -21,6 +23,7 @@ from tests.test_parsing import parsed_vasp_example # pylint: disable=unused-imp
from tests.test_parsing import parsed_template_example # pylint: disable=unused-import
from tests.test_parsing import parsed_example # pylint: disable=unused-import
from tests.test_parsing import parse_file
from tests.test_parsing import parsed_template_no_system # pylint: disable=unused-import
def run_normalize(backend: LocalBackend) -> LocalBackend:
......@@ -49,6 +52,20 @@ def normalized_template_example(parsed_template_example) -> LocalBackend:
return run_normalize(parsed_template_example)
def run_normalize_for_structure(atoms: Atoms) -> LocalBackend:
template = parsed_template_no_system()
# Fill structural information
gid = template.openSection("section_system")
template.addArrayValues("atom_positions", atoms.get_positions() * 1E-10)
template.addArrayValues("atom_labels", atoms.get_chemical_symbols())
template.addArrayValues("simulation_cell", atoms.get_cell() * 1E-10)
template.addArrayValues("configuration_periodic_dimensions", atoms.get_pbc())
template.closeSection("section_system", gid)
return run_normalize(template)
@pytest.fixture(scope='session')
def geometry_optimization() -> LocalBackend:
parser_name = "parsers/template"
......
......@@ -13,11 +13,16 @@
# limitations under the License.
import pytest
from hashlib import sha512
import numpy as np
from ase import Atoms
from matid.symmetry.wyckoffset import WyckoffSet
from nomad.parsing import LocalBackend
from nomad.normalizing import structure
from nomad.metainfo.encyclopedia import Encyclopedia
from tests.normalizing.conftest import geometry_optimization, molecular_dynamics, phonon, two_d, bulk # pylint: disable=unused-import
from tests.normalizing.conftest import run_normalize_for_structure, geometry_optimization, molecular_dynamics, phonon, two_d, bulk # pylint: disable=unused-import
def test_geometry_optimization(geometry_optimization: LocalBackend):
......@@ -92,3 +97,86 @@ def test_2d_metainfo(two_d: LocalBackend):
assert enc.material.formula_reduced == "C"
assert np.allclose(enc.calculation.lattice_parameters, [2.46559821e-10, 2.46559821e-10, 0, 120 / 180 * np.pi, 0, 0])
assert np.array_equal(enc.material.periodicity, [0, 1])
def test_2d_graphene():
"""Tests that graphene in different supercells is detected always as the same material."""
# Expected information for graphene
wyckoff_sets = [WyckoffSet(
wyckoff_letter="c",
element="C",
indices=[0, 1]
)]
space_group_number = 191
norm_hash_string = structure.get_symmetry_string(space_group_number, wyckoff_sets)
graphene_material_hash = sha512(norm_hash_string.encode('utf-8')).hexdigest()
# Graphene orthogonal cell
atoms = Atoms(
symbols=["C", "C", "C", "C"],
positions=[
[2.84, 7.5, 6.148780366869514e-1],
[3.55, 7.5, 1.8446341100608543],
[7.1e-1, 7.5, 1.8446341100608543],
[1.42, 7.5, 6.148780366869514e-1]
],
cell=[
[4.26, 0.0, 0.0],
[0.0, 15, 0.0],
[0.0, 0.0, 2.4595121467478055]
],
pbc=True
)
backend = run_normalize_for_structure(atoms)
enc = backend.get_mi2_section(Encyclopedia.m_def)
assert enc.material.material_hash == graphene_material_hash
# Graphene orthogonal cell, multiplied
atoms = Atoms(
symbols=["C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C"],
positions=[
[7.1, 6, 6.148780366869514e-1],
[7.81, 6, 1.8446341100608543],
[7.1, 6, 3.074390183434757],
[7.81, 6, 4.30414625680866],
[4.97, 6, 1.8446341100608543],
[5.68, 6, 3.074390183434757],
[4.97, 6, 4.30414625680866],
[5.68, 6, 6.148780366869514e-1],
[2.84, 6, 6.148780366869514e-1],
[3.55, 6, 1.8446341100608543],
[2.84, 6, 3.074390183434757],
[3.55, 6, 4.30414625680866],
[7.1e-1, 6, 1.8446341100608543],
[1.42, 6, 3.074390183434757],
[7.1e-1, 6, 4.30414625680866],
[1.42, 6, 6.148780366869514e-1]
],
cell=[
[8.52, 0.0, 0.0],
[0.0, 12, 0.0],
[0.0, 0.0, 4.919024293495611]
],
pbc=True
)
backend = run_normalize_for_structure(atoms)
enc = backend.get_mi2_section(Encyclopedia.m_def)
assert enc.material.material_hash == graphene_material_hash
# Graphene primitive cell
atoms = Atoms(
symbols=["C", "C"],
positions=[
[0, 1.42, 6],
[1.2297560733739028, 7.100000000000001e-1, 6]
],
cell=[
[2.4595121467478055, 0.0, 0.0],
[-1.2297560733739028, 2.13, 0.0],
[0.0, 0.0, 12]
],
pbc=True
)
backend = run_normalize_for_structure(atoms)
enc = backend.get_mi2_section(Encyclopedia.m_def)
assert enc.material.material_hash == graphene_material_hash
......@@ -144,7 +144,6 @@ def test_system_classification(bulk, two_d):
"""
# Bulk system
assert bulk.get_value('system_type') == "bulk"
# 2D system
assert two_d.get_value('system_type') == "2D"
......
......@@ -350,6 +350,12 @@ def parsed_template_example() -> LocalBackend:
'parsers/template', 'tests/data/parsers/template.json')
@pytest.fixture(scope="session")
def parsed_template_no_system() -> LocalBackend:
return run_parser(
'parsers/template', 'tests/data/parsers/template_no_system.json')
def parse_file(parser_name_and_mainfile) -> LocalBackend:
parser_name, mainfile = parser_name_and_mainfile
return run_parser(parser_name, mainfile)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment