Commits (7)
......@@ -52,3 +52,5 @@ TAGS
lib/
env/
abinitparser.egg-info/
Metadata-Version: 1.0
Name: abinitparser
Version: 0.1
Summary: NOMAD parser implementation for Abinit.
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: APACHE 2.0
Description: UNKNOWN
Platform: UNKNOWN
README.md
setup.py
./abinitparser/AbinitXC.py
./abinitparser/__init__.py
./abinitparser/parser.py
./abinitparser/setup_paths.py
./abinitparser.egg-info/PKG-INFO
./abinitparser.egg-info/SOURCES.txt
./abinitparser.egg-info/dependency_links.txt
./abinitparser.egg-info/requires.txt
./abinitparser.egg-info/top_level.txt
\ No newline at end of file
import sys
from nomad.metainfo import Environment
from nomad.metainfo.legacy import LegacyMetainfoEnvironment
import abinitparser.metainfo.abinit
import nomad.datamodel.metainfo.common
import nomad.datamodel.metainfo.public
import nomad.datamodel.metainfo.general
import abinitparser.metainfo.abinit_autogenerated
m_env = LegacyMetainfoEnvironment()
m_env.m_add_sub_section(Environment.packages, sys.modules['abinitparser.metainfo.abinit'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.common'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.public'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['nomad.datamodel.metainfo.general'].m_package) # type: ignore
m_env.m_add_sub_section(Environment.packages, sys.modules['abinitparser.metainfo.abinit_autogenerated'].m_package) # type: ignore
import numpy as np # pylint: disable=unused-import
import typing # pylint: disable=unused-import
from nomad.metainfo import ( # pylint: disable=unused-import
MSection, MCategory, Category, Package, Quantity, Section, SubSection, SectionProxy,
Reference
)
from nomad.metainfo.legacy import LegacyDefinition
from abinitparser.metainfo import abinit_autogenerated
from nomad.datamodel.metainfo import public
m_package = Package(
name='abinit_nomadmetainfo_json',
description='None',
a_legacy=LegacyDefinition(name='abinit.nomadmetainfo.json'))
class x_abinit_section_stress_tensor(MSection):
'''
Section describing the stress tensor
'''
m_def = Section(validate=False, a_legacy=LegacyDefinition(name='x_abinit_section_stress_tensor'))
x_abinit_stress_tensor_xx = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
xx component of the stress tensor
''',
a_legacy=LegacyDefinition(name='x_abinit_stress_tensor_xx'))
x_abinit_stress_tensor_yy = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
yy component of the stress tensor
''',
a_legacy=LegacyDefinition(name='x_abinit_stress_tensor_yy'))
x_abinit_stress_tensor_zz = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
zz component of the stress tensor
''',
a_legacy=LegacyDefinition(name='x_abinit_stress_tensor_zz'))
x_abinit_stress_tensor_zy = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
zy component of the stress tensor
''',
a_legacy=LegacyDefinition(name='x_abinit_stress_tensor_zy'))
x_abinit_stress_tensor_zx = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
zx component of the stress tensor
''',
a_legacy=LegacyDefinition(name='x_abinit_stress_tensor_zx'))
x_abinit_stress_tensor_yx = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
yx component of the stress tensor
''',
a_legacy=LegacyDefinition(name='x_abinit_stress_tensor_yx'))
class x_abinit_section_dataset_header(MSection):
'''
-
'''
m_def = Section(validate=False, a_legacy=LegacyDefinition(name='x_abinit_section_dataset_header'))
x_abinit_dataset_number = Quantity(
type=np.dtype(np.int32),
shape=[],
description='''
Dataset number
''',
a_legacy=LegacyDefinition(name='x_abinit_dataset_number'))
x_abinit_vprim_1 = Quantity(
type=str,
shape=[],
description='''
Primitive axis 1
''',
a_legacy=LegacyDefinition(name='x_abinit_vprim_1'))
x_abinit_vprim_2 = Quantity(
type=str,
shape=[],
description='''
Primitive axis 2
''',
a_legacy=LegacyDefinition(name='x_abinit_vprim_2'))
x_abinit_vprim_3 = Quantity(
type=str,
shape=[],
description='''
Primitive axis 3
''',
a_legacy=LegacyDefinition(name='x_abinit_vprim_3'))
class x_abinit_section_var(MSection):
'''
-
'''
m_def = Section(validate=False, a_legacy=LegacyDefinition(name='x_abinit_section_var'))
x_abinit_vardtset = Quantity(
type=np.dtype(np.int32),
shape=[],
description='''
Variable dataset number
''',
a_legacy=LegacyDefinition(name='x_abinit_vardtset'))
x_abinit_varname = Quantity(
type=str,
shape=[],
description='''
Variable name
''',
a_legacy=LegacyDefinition(name='x_abinit_varname'))
x_abinit_varvalue = Quantity(
type=str,
shape=[],
description='''
Variable value
''',
a_legacy=LegacyDefinition(name='x_abinit_varvalue'))
x_abinit_vartruncation = Quantity(
type=str,
shape=[],
description='''
Variable truncation length
''',
a_legacy=LegacyDefinition(name='x_abinit_vartruncation'))
class section_run(public.section_run):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_run'))
x_abinit_parallel_compilation = Quantity(
type=str,
shape=[],
description='''
Parallel or sequential compilation
''',
a_legacy=LegacyDefinition(name='x_abinit_parallel_compilation'))
x_abinit_start_date = Quantity(
type=str,
shape=[],
description='''
Start date as string
''',
a_legacy=LegacyDefinition(name='x_abinit_start_date'))
x_abinit_start_time = Quantity(
type=str,
shape=[],
description='''
Start time as string
''',
a_legacy=LegacyDefinition(name='x_abinit_start_time'))
x_abinit_input_file = Quantity(
type=str,
shape=[],
description='''
Input file name
''',
a_legacy=LegacyDefinition(name='x_abinit_input_file'))
x_abinit_output_file = Quantity(
type=str,
shape=[],
description='''
Output file name
''',
a_legacy=LegacyDefinition(name='x_abinit_output_file'))
x_abinit_input_files_root = Quantity(
type=str,
shape=[],
description='''
Root for input files
''',
a_legacy=LegacyDefinition(name='x_abinit_input_files_root'))
x_abinit_output_files_root = Quantity(
type=str,
shape=[],
description='''
Root for output files
''',
a_legacy=LegacyDefinition(name='x_abinit_output_files_root'))
x_abinit_total_cpu_time = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Total CPU time
''',
a_legacy=LegacyDefinition(name='x_abinit_total_cpu_time'))
x_abinit_total_wallclock_time = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Total wallclock time
''',
a_legacy=LegacyDefinition(name='x_abinit_total_wallclock_time'))
x_abinit_completed = Quantity(
type=str,
shape=[],
description='''
Message that the calculation was completed
''',
a_legacy=LegacyDefinition(name='x_abinit_completed'))
x_abinit_section_var = SubSection(
sub_section=SectionProxy('x_abinit_section_var'),
repeats=True,
a_legacy=LegacyDefinition(name='x_abinit_section_var'))
class section_system(public.section_system):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_system'))
x_abinit_atom_xcart_final = Quantity(
type=str,
shape=[],
description='''
Cartesian coordinates of an atom at the end of the dataset
''',
a_legacy=LegacyDefinition(name='x_abinit_atom_xcart_final'))
x_abinit_atom_xcart = Quantity(
type=str,
shape=[],
description='''
Cartesian coordinates of an atom at the end of a single configuration calculation
''',
a_legacy=LegacyDefinition(name='x_abinit_atom_xcart'))
class section_single_configuration_calculation(public.section_single_configuration_calculation):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_single_configuration_calculation'))
x_abinit_magnetisation = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Total magnetisation.
''',
a_legacy=LegacyDefinition(name='x_abinit_magnetisation'))
x_abinit_fermi_energy = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Fermi energy.
''',
a_legacy=LegacyDefinition(name='x_abinit_fermi_energy'))
x_abinit_single_configuration_calculation_converged = Quantity(
type=str,
shape=[],
description='''
Determines whether a single configuration calculation is converged.
''',
a_legacy=LegacyDefinition(name='x_abinit_single_configuration_calculation_converged'))
x_abinit_atom_force = Quantity(
type=str,
shape=[],
description='''
Force acting on an atom at the end of a single configuration calculation
''',
a_legacy=LegacyDefinition(name='x_abinit_atom_force'))
x_abinit_atom_force_final = Quantity(
type=str,
shape=[],
description='''
Force acting on an atom at the end of the dataset
''',
a_legacy=LegacyDefinition(name='x_abinit_atom_force_final'))
x_abinit_energy_kinetic = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Kinetic energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_kinetic'))
x_abinit_energy_hartree = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Hartree energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_hartree'))
x_abinit_energy_xc = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
XC energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_xc'))
x_abinit_energy_ewald = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Ewald energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_ewald'))
x_abinit_energy_psp_core = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Pseudopotential core energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_psp_core'))
x_abinit_energy_psp_local = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Local pseudopotential energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_psp_local'))
x_abinit_energy_psp_nonlocal = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Non-local pseudopotential energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_psp_nonlocal'))
x_abinit_energy_internal = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Internal energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_internal'))
x_abinit_energy_ktentropy = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
-kT*entropy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_ktentropy'))
x_abinit_energy_band = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Band energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_band'))
x_abinit_energy_total = Quantity(
type=np.dtype(np.float64),
shape=[],
description='''
Total energy
''',
a_legacy=LegacyDefinition(name='x_abinit_energy_total'))
x_abinit_section_stress_tensor = SubSection(
sub_section=SectionProxy('x_abinit_section_stress_tensor'),
repeats=True,
a_legacy=LegacyDefinition(name='x_abinit_section_stress_tensor'))
class section_eigenvalues(public.section_eigenvalues):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='section_eigenvalues'))
x_abinit_kpt = Quantity(
type=str,
shape=[],
description='''
The reduced coordinates of a k-point
''',
a_legacy=LegacyDefinition(name='x_abinit_kpt'))
x_abinit_wtk = Quantity(
type=str,
shape=[],
description='''
A k-point weight
''',
a_legacy=LegacyDefinition(name='x_abinit_wtk'))
x_abinit_eigenvalues = Quantity(
type=str,
shape=[],
description='''
List of eigenvalues on a given k-point
''',
a_legacy=LegacyDefinition(name='x_abinit_eigenvalues'))
x_abinit_occupations = Quantity(
type=str,
shape=[],
description='''
List of occupations on a given k-point
''',
a_legacy=LegacyDefinition(name='x_abinit_occupations'))
class x_abinit_section_dataset(abinit_autogenerated.x_abinit_section_dataset):
m_def = Section(validate=False, extends_base_section=True, a_legacy=LegacyDefinition(name='x_abinit_section_dataset'))
x_abinit_geometry_optimization_converged = Quantity(
type=str,
shape=[],
description='''
Determines whether a geometry optimization is converged.
''',
a_legacy=LegacyDefinition(name='x_abinit_geometry_optimization_converged'))
x_abinit_eig_filename = Quantity(
type=str,
shape=[],
description='''
Name of file where the eigenvalues were written to.
''',
a_legacy=LegacyDefinition(name='x_abinit_eig_filename'))
x_abinit_section_dataset_header = SubSection(
sub_section=SectionProxy('x_abinit_section_dataset_header'),
repeats=True,
a_legacy=LegacyDefinition(name='x_abinit_section_dataset_header'))
m_package.__init_metainfo__()
This diff is collapsed.
......@@ -52,12 +52,6 @@ ABINIT_GEO_OPTIMIZATION = {
20: "diis"
}
# loading metadata from nomad-meta-info/meta_info/nomad_meta_info/abinit.nomadmetainfo.json
import nomad_meta_info
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)), "abinit.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
class ABINITContext(object):
"""context for the sample parser"""
......@@ -152,7 +146,7 @@ class ABINITContext(object):
if self.input["x_abinit_var_tolmxf"] is not None:
backend.addValue("geometry_optimization_threshold_force",
unit_conversion.convert_unit(self.input["x_abinit_var_tolmxf"][-1], "forceAu"))
unit_conversion.convert_unit(self.input["x_abinit_var_tolmxf"][-1], "hartree / bohr"))
if self.input["x_abinit_var_tolmxde"] is not None:
backend.addValue("geometry_optimization_energy_change",
unit_conversion.convert_unit(self.input["x_abinit_var_tolmxde"][-1], "hartree"))
......@@ -200,7 +194,7 @@ class ABINITContext(object):
n_atom = 0
for force_string in atom_forces_list:
for dir in range(3):
atom_forces[n_atom, dir] = unit_conversion.convert_unit(float(force_string.split()[dir]), "forceAu")
atom_forces[n_atom, dir] = unit_conversion.convert_unit(float(force_string.split()[dir]), "hartree / bohr")
n_atom += 1
backend.addArrayValues("atom_forces_raw", atom_forces)
......@@ -364,7 +358,12 @@ class ABINITContext(object):
for z in self.input["x_abinit_var_znucl"][-1]:
symbol = chemical_symbols[int(z)]
species_count[symbol] += 1
atom_types.append(symbol+str(species_count[symbol]))
if species_count[symbol] > 1:
atom_type = symbol + str(species_count[symbol])
else:
atom_type = symbol
atom_types.append(atom_type)
# Grabs an array with the dtype of meta name atom_labels and
# shape of self.input('x_abinit..').
atom_labels = backend.arrayForMetaInfo("atom_labels", self.input["x_abinit_var_natom"][-1])
......@@ -372,14 +371,7 @@ class ABINITContext(object):
for atom_index in range(self.input["x_abinit_var_natom"][-1]):
atom_labels[atom_index] = atom_types[self.input["x_abinit_var_typat"][-1][atom_index] - 1]
# NOMAD-FAIRD (dts@physik.hu-berlin.de)
# We end up with a list of atom labels. The problem is that the ase library
# compalains about receiving lists such as ['F2', 'B', C']. The 2 in the F is the
# problem. So let's join the strings in the list. Ase still won't like
# ['F2BC'] so we return the string inside the list instead.
atom_labels_nomad_faird = ''.join(atom_labels)
backend.addArrayValues("atom_labels", atom_labels_nomad_faird)
backend.addArrayValues("atom_labels", atom_labels)
if section["x_abinit_atom_xcart"] is not None:
atom_xcart_list = section["x_abinit_atom_xcart"]
......@@ -434,7 +426,7 @@ class ABINITContext(object):
"""Trigger called when x_abinit_section_input is closed.
"""
dataset_vars = {}
for varname in metaInfoEnv.infoKinds.keys():
for varname in backend.superBackend.metaInfoEnv().infoKinds.keys():
if "x_abinit_var_" in varname:
dataset_vars[varname] = None
......@@ -472,7 +464,7 @@ class ABINITContext(object):
for varname, varvalue in dataset_vars.items():
meta_info = metaInfoEnv.infoKindEl(varname)
meta_info = backend.superBackend.metaInfoEnv().infoKindEl(varname)
# Skip optional variables that do not have a value or that are not defined in the meta-info
if varvalue is None or meta_info is None:
......@@ -515,7 +507,11 @@ class ABINITContext(object):
for mo in re.finditer(dim_regex, dim):
dim = re.sub(mo.group("abi_var"), str(dataset_vars[mo.group("abi_var")]), dim)
# In some cases the dimension is given as a numerical expression that needs to be evaluated
dim = eval(dim)
try:
dim = eval(dim)
except SyntaxError as e:
print(dim, meta_info.name, meta_info.shape)
raise e
shape.append(dim)
backend.addArrayValues(varname, array.reshape(shape))
......@@ -1151,11 +1147,11 @@ class AbinitParser():
from unittest.mock import patch
logging.info('abinit parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
backend = self.backend_factory("abinit.nomadmetainfo.json")
with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]):
mainFunction(
mainFileDescription,
metaInfoEnv,
None,
parserInfo,
cachingLevelForMetaName = {'x_abinit_section_var': CachingLevel.Cache
},
......@@ -1163,12 +1159,3 @@ class AbinitParser():
superBackend=backend)
return backend
if __name__ == "__main__":
superContext = ABINITContext()
mainFunction(mainFileDescription=mainFileDescription,
metaInfoEnv=metaInfoEnv,
parserInfo=parserInfo,
cachingLevelForMetaName={'x_abinit_section_var': CachingLevel.Cache
},
superContext=superContext)
# Copyright 2016-2018 Micael Oliveira, Fawzi Mohamed
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, os, os.path
baseDir = os.path.dirname(os.path.abspath(__file__))
commonDir = os.path.normpath(os.path.join(baseDir, "../../../../python-common/common/python"))
if commonDir not in sys.path:
sys.path.insert(0, commonDir)