Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
parser-wien2k
Compare Revisions
16f7a7f6909dbe16908d1be2e1fa03d3bddd17b5...d58ac9b61ba2c9e82f50a30c2c234778743d51ad
Commits (2)
Fixed issues in reading the WIEN2k structure file.
· 4719cca1
Lauri Himanen
authored
Jul 16, 2020
4719cca1
Added exception handling.
· d58ac9b6
Lauri Himanen
authored
Jul 16, 2020
d58ac9b6
Hide whitespace changes
Inline
Side-by-side
wien2kparser/parser_wien2k.py
View file @
d58ac9b6
from
builtins
import
object
# import setup_paths
import
numpy
as
np
import
ase.io
import
os
import
sys
...
...
@@ -13,7 +14,7 @@ import wien2kparser.wien2k_parser_in1c as wien2k_parser_in1c
import
wien2kparser.wien2k_parser_in2c
as
wien2k_parser_in2c
import
wien2kparser.wien2k_parser_in1
as
wien2k_parser_in1
import
wien2kparser.wien2k_parser_in2
as
wien2k_parser_in2
import
logging
as
_logging
import
logging
from
nomad.parsing.legacy
import
CoESimpleMatcherParser
...
...
@@ -173,7 +174,6 @@ class Wien2kContext(object):
if
atom_labels
is
not
None
:
backend
.
addArrayValues
(
'atom_labels'
,
np
.
asarray
(
atom_labels
))
# atom force
atom_force
=
[]
for
i
in
[
'x'
,
'y'
,
'z'
]:
...
...
@@ -184,20 +184,34 @@ class Wien2kContext(object):
# need to transpose array since its shape is [number_of_atoms,3] in\the metadata
backend
.
addArrayValues
(
'atom_forces'
,
np
.
transpose
(
np
.
asarray
(
atom_force
)))
# Parse the structure file
mainFile
=
self
.
parser
.
fIn
.
fIn
.
name
fName
=
mainFile
[:
-
4
]
+
".struct"
if
os
.
path
.
exists
(
fName
):
structSuperContext
=
wien2k_parser_struct
.
Wien2kStructContext
()
structParser
=
AncillaryParser
(
fileDescription
=
wien2k_parser_struct
.
buildStructureMatchers
(),
parser
=
self
.
parser
,
cachingLevelForMetaName
=
wien2k_parser_struct
.
get_cachingLevelForMetaName
(
self
.
metaInfoEnv
,
CachingLevel
.
PreOpenedIgnore
),
superContext
=
structSuperContext
)
with
open
(
fName
)
as
fIn
:
structParser
.
parseFile
(
fIn
)
# ASE does not support reading file object for WIEN2k structure files.
try
:
atoms
=
ase
.
io
.
read
(
fName
,
format
=
"struct"
)
except
Exception
:
logging
.
error
(
"Could not read/parse the WIEN2k structure file."
)
else
:
pos
=
atoms
.
get_positions
()
*
1E-10
symbols
=
atoms
.
get_chemical_symbols
()
cell
=
atoms
.
get_cell
()
*
1E-10
pbc
=
atoms
.
get_pbc
()
backend
.
addArrayValues
(
'lattice_vectors'
,
cell
)
backend
.
addArrayValues
(
"configuration_periodic_dimensions"
,
pbc
)
backend
.
addValue
(
"atom_labels"
,
symbols
)
backend
.
addArrayValues
(
'atom_positions'
,
pos
)
with
open
(
fName
,
"r"
)
as
fin
:
structSuperContext
=
wien2k_parser_struct
.
Wien2kStructContext
()
structParser
=
AncillaryParser
(
fileDescription
=
wien2k_parser_struct
.
buildStructureMatchers
(),
parser
=
self
.
parser
,
cachingLevelForMetaName
=
wien2k_parser_struct
.
get_cachingLevelForMetaName
(
self
.
metaInfoEnv
,
CachingLevel
.
PreOpenedIgnore
),
superContext
=
structSuperContext
)
structParser
.
parseFile
(
fin
)
def
onClose_section_scf_iteration
(
self
,
backend
,
gIndex
,
section
):
#Trigger called when section_scf_iteration is closed.
...
...
wien2kparser/wien2k_parser_struct.py
View file @
d58ac9b6
...
...
@@ -30,7 +30,8 @@ __maintainer__ = "Daria M. Tomecka"
__email__
=
"tomeckadm@gmail.com;"
__date__
=
"15/05/2017"
class
Wien2kStructContext
(
object
):
class
Wien2kStructContext
():
"""context for wien2k struct parser"""
def
__init__
(
self
):
...
...
@@ -46,46 +47,6 @@ class Wien2kStructContext(object):
# allows to reset values if the same superContext is used to parse different files
self
.
initialize_values
()
def
onClose_section_system
(
self
,
backend
,
gIndex
,
section
):
# unit_cell
unit_cell_params
=
[]
for
i
in
[
'a'
,
'b'
,
'c'
]:
uci
=
section
[
'x_wien2k_unit_cell_param_'
+
i
]
#if uci is not None:
unit_cell_params
.
append
(
uci
[
0
])
for
i
in
[
'alfa'
,
'beta'
,
'gamma'
]:
uci
=
section
[
'x_wien2k_angle_between_unit_axis_'
+
i
]
# if uci is not None:
unit_cell_params
.
append
(
uci
[
0
])
unit_cell
=
ase
.
geometry
.
cellpar_to_cell
(
unit_cell_params
)
backend
.
addArrayValues
(
'simulation_cell'
,
unit_cell
)
backend
.
addArrayValues
(
"configuration_periodic_dimensions"
,
np
.
ones
(
3
,
dtype
=
bool
))
equiv_atoms
=
section
[
"x_wien2k_section_equiv_atoms"
]
#logging.error("section: %s", section)
labels
=
[]
pos
=
[]
for
eqAtoms
in
equiv_atoms
:
label
=
eqAtoms
[
"x_wien2k_atom_name"
][
0
]
x
=
eqAtoms
[
"x_wien2k_atom_pos_x"
]
y
=
eqAtoms
[
"x_wien2k_atom_pos_y"
]
z
=
eqAtoms
[
"x_wien2k_atom_pos_z"
]
#logging.error("equiv_atoms: %s x %s y %s z %s",eqAtoms, x, y, z)
if
len
(
x
)
!=
len
(
y
)
or
len
(
x
)
!=
len
(
z
):
raise
Exception
(
"incorrect parsing, different number of x,y,z components"
)
groupPos
=
[[
x
[
i
],
y
[
i
],
z
[
i
]]
for
i
in
range
(
len
(
x
))]
nAt
=
len
(
groupPos
)
labels
+=
[
label
for
i
in
range
(
nAt
)]
pos
+=
groupPos
backend
.
addValue
(
"atom_labels"
,
labels
)
#backend.addArrayValues("atom_positions", np.dot(pos,unit_cell))
#backend.addArrayValues('atom_positions', np.transpose(np.asarray(pos)))
backend
.
addArrayValues
(
'atom_positions'
,
np
.
asarray
(
pos
))
# description of the input
def
buildStructureMatchers
():
...
...