Skip to content

Commit

Permalink
Add date_start and date_end for openmx parser + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrodlova authored and ondracka committed Apr 10, 2024
1 parent 8220643 commit 92adfa5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
26 changes: 25 additions & 1 deletion electronicparsers/openmx/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import logging
from typing import Optional
import numpy as np
from datetime import datetime
import re
import io
from os import path

from nomad.datamodel import EntryArchive
from nomad.units import ureg as units
from runschema.run import Run, Program
from runschema.run import Run, Program, TimeRun
from runschema.calculation import (
Calculation,
ScfIteration,
Expand Down Expand Up @@ -164,6 +165,19 @@ def convert_eigenvalues(string):

mainfile_parser = TextParser(
quantities=[
Quantity(
'date_start',
r'\s+([A-Z]{1}[a-z]{2}\s[A-Z]{1}[a-z]{2}\s\d{1,2}\s\d{2}:\d{2}:\d{2}\s\d{4})',
repeats=False,
flatten=False,
dtype=str,
),

Quantity(
'elapsed_time',
r'\s+Elapsed.Time.\s+([\d.]+)',
repeats=False,
),
Quantity(
'program_version',
r'This calculation was performed by OpenMX Ver. ([\d\.]+)\s*',
Expand Down Expand Up @@ -716,6 +730,16 @@ def parse(self, mainfile: str, archive: EntryArchive, logger):
sec_run.program = Program(
name='OpenMX', version=str(mainfile_parser.get('program_version'))
)
date_start = mainfile_parser.get('date_start')
date_start_timestamp = datetime.strptime(
date_start, '%a %b %d %H:%M:%S %Y').timestamp()
sec_run.time_run = TimeRun()
sec_run.time_run.date_start = date_start_timestamp

elapsed_time = mainfile_parser.get('elapsed_time')
if elapsed_time is not None:
date_end = date_start_timestamp + elapsed_time
sec_run.time_run.date_end = date_end

sec_run.clean_end = mainfile_parser.get('have_timing') is not None

Expand Down
21 changes: 21 additions & 0 deletions tests/test_openmxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pytest
import logging
import numpy as np
from datetime import datetime

from nomad.datamodel import EntryArchive
from nomad.units import ureg as units
Expand Down Expand Up @@ -99,6 +100,13 @@ def test_AlN(parser):
run = archive.run[0]
assert run.program.version == '3.9.2'
assert run.clean_end

date_start_timestamp = datetime(2021, 4, 17, 18, 14, 52).timestamp()
assert run.time_run.date_start.magnitude == date_start_timestamp

date_end_timestamp = datetime(2021, 4, 17, 18, 19, 12, 811000).timestamp()
assert run.time_run.date_end.magnitude == date_end_timestamp

scc = run.calculation
assert len(scc) == 5
assert scc[0].energy.total.value.magnitude == approx(Ha_to_J(-25.194346653540))
Expand Down Expand Up @@ -184,6 +192,13 @@ def test_C2N2(parser):
run = archive.run[0]
assert run.program.version == '3.9.2'
assert run.clean_end

date_start_timestamp = datetime(2021, 5, 27, 9, 7, 27).timestamp()
assert run.time_run.date_start.magnitude == date_start_timestamp

date_end_timestamp = datetime(2021, 5, 27, 9, 13, 7, 525000).timestamp()
assert run.time_run.date_end.magnitude == date_end_timestamp

scc = run.calculation
assert len(scc) == 100
assert scc[0].temperature.magnitude == approx(300.0)
Expand Down Expand Up @@ -253,6 +268,12 @@ def test_CrO2(parser):

run = archive.run[0]

date_start_timestamp = datetime(2021, 7, 16, 11, 49, 7).timestamp()
assert run.time_run.date_start.magnitude == date_start_timestamp

date_end_timestamp = datetime(2021, 7, 16, 11, 50, 11, 133000).timestamp()
assert run.time_run.date_end.magnitude == date_end_timestamp

method = run.method[0]
assert method.electronic.n_spin_channels == 2
assert method.electronic.method == 'DFT+U'
Expand Down

0 comments on commit 92adfa5

Please sign in to comment.