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
nomad-FAIR
Commits
8ea11000
Commit
8ea11000
authored
Jul 28, 2020
by
Alvin Noe Ladines
Committed by
Markus Scheidgen
Jul 30, 2020
Browse files
Removed backed in normalizing
parent
f7e22b11
Changes
7
Hide whitespace changes
Inline
Side-by-side
nomad/normalizing/encyclopedia/basisset.py
View file @
8ea11000
...
@@ -4,18 +4,17 @@ import numpy as np
...
@@ -4,18 +4,17 @@ import numpy as np
from
typing
import
Tuple
,
List
from
typing
import
Tuple
,
List
from
nomad.units
import
ureg
from
nomad.units
import
ureg
from
nomad.parsing.legacy
import
Backend
from
nomad.metainfo
import
Section
from
nomad.metainfo
import
Section
from
nomad.utils
import
RestrictedDict
from
nomad.utils
import
RestrictedDict
def
get_basis_set
(
context
,
backend
:
Backend
,
logger
)
->
RestrictedDict
:
def
get_basis_set
(
context
,
entry_archive
,
logger
)
->
RestrictedDict
:
"""Decide which type of basis set settings are applicable to the entry and
"""Decide which type of basis set settings are applicable to the entry and
return a corresponding settings as a RestrictedDict.
return a corresponding settings as a RestrictedDict.
Args:
Args:
context: The calculation context.
context: The calculation context.
backend: Backend
from which values are extracted.
entry_archive: EntryArchive
from which values are extracted.
logger: Shared logger.
logger: Shared logger.
Returns:
Returns:
...
@@ -24,11 +23,11 @@ def get_basis_set(context, backend: Backend, logger) -> RestrictedDict:
...
@@ -24,11 +23,11 @@ def get_basis_set(context, backend: Backend, logger) -> RestrictedDict:
returns None.
returns None.
"""
"""
settings
:
BasisSet
=
None
settings
:
BasisSet
=
None
program_name
=
backend
.
entry_archive
.
section_run
[
0
].
program_name
program_name
=
entry_archive
.
section_run
[
0
].
program_name
if
program_name
==
"exciting"
:
if
program_name
==
"exciting"
:
settings
=
BasisSetExciting
(
context
,
backend
,
logger
)
settings
=
BasisSetExciting
(
context
,
entry_archive
,
logger
)
elif
program_name
==
"FHI-aims"
:
elif
program_name
==
"FHI-aims"
:
settings
=
BasisSetFHIAims
(
context
,
backend
,
logger
)
settings
=
BasisSetFHIAims
(
context
,
entry_archive
,
logger
)
else
:
else
:
return
None
return
None
...
@@ -40,11 +39,11 @@ class BasisSet(ABC):
...
@@ -40,11 +39,11 @@ class BasisSet(ABC):
subclasses that inherit this class and hierarchically add new mandatory and
subclasses that inherit this class and hierarchically add new mandatory and
optional settings with the setup()-function.
optional settings with the setup()-function.
"""
"""
def
__init__
(
self
,
context
,
backend
,
logger
):
def
__init__
(
self
,
context
,
entry_archive
,
logger
):
"""
"""
"""
"""
self
.
_ctx
=
context
self
.
_ctx
=
context
self
.
_
backend
=
backend
self
.
_
entry_archive
=
entry_archive
self
.
_logger
=
logger
self
.
_logger
=
logger
mandatory
,
optional
=
self
.
setup
()
mandatory
,
optional
=
self
.
setup
()
self
.
settings
=
RestrictedDict
(
mandatory
,
optional
,
forbidden_values
=
[
None
])
self
.
settings
=
RestrictedDict
(
mandatory
,
optional
,
forbidden_values
=
[
None
])
...
...
nomad/normalizing/encyclopedia/encyclopedia.py
View file @
8ea11000
...
@@ -180,32 +180,32 @@ class EncyclopediaNormalizer(Normalizer):
...
@@ -180,32 +180,32 @@ class EncyclopediaNormalizer(Normalizer):
# Fill structure related metainfo
# Fill structure related metainfo
struct
:
Any
=
None
struct
:
Any
=
None
if
context
.
material_type
==
Material
.
material_type
.
type
.
bulk
:
if
context
.
material_type
==
Material
.
material_type
.
type
.
bulk
:
struct
=
MaterialBulkNormalizer
(
self
.
backend
,
self
.
logger
)
struct
=
MaterialBulkNormalizer
(
self
.
entry_archive
,
self
.
logger
)
elif
context
.
material_type
==
Material
.
material_type
.
type
.
two_d
:
elif
context
.
material_type
==
Material
.
material_type
.
type
.
two_d
:
struct
=
Material2DNormalizer
(
self
.
backend
,
self
.
logger
)
struct
=
Material2DNormalizer
(
self
.
entry_archive
,
self
.
logger
)
elif
context
.
material_type
==
Material
.
material_type
.
type
.
one_d
:
elif
context
.
material_type
==
Material
.
material_type
.
type
.
one_d
:
struct
=
Material1DNormalizer
(
self
.
backend
,
self
.
logger
)
struct
=
Material1DNormalizer
(
self
.
entry_archive
,
self
.
logger
)
if
struct
is
not
None
:
if
struct
is
not
None
:
struct
.
normalize
(
context
)
struct
.
normalize
(
context
)
# Fill method related metainfo
# Fill method related metainfo
method
=
None
method
=
None
if
context
.
method_type
==
Method
.
method_type
.
type
.
DFT
or
context
.
method_type
==
Method
.
method_type
.
type
.
DFTU
:
if
context
.
method_type
==
Method
.
method_type
.
type
.
DFT
or
context
.
method_type
==
Method
.
method_type
.
type
.
DFTU
:
method
=
MethodDFTNormalizer
(
self
.
_backend
,
self
.
logger
)
method
=
MethodDFTNormalizer
(
self
.
entry_archive
,
self
.
logger
)
elif
context
.
method_type
==
Method
.
method_type
.
type
.
GW
:
elif
context
.
method_type
==
Method
.
method_type
.
type
.
GW
:
method
=
MethodGWNormalizer
(
self
.
_backend
,
self
.
logger
)
method
=
MethodGWNormalizer
(
self
.
entry_archive
,
self
.
logger
)
if
method
is
not
None
:
if
method
is
not
None
:
method
.
normalize
(
context
)
method
.
normalize
(
context
)
# Fill properties related metainfo
# Fill properties related metainfo
properties
=
PropertiesNormalizer
(
self
.
backend
,
self
.
logger
)
properties
=
PropertiesNormalizer
(
self
.
entry_archive
,
self
.
logger
)
properties
.
normalize
(
context
)
properties
.
normalize
(
context
)
def
normalize
(
self
,
logger
=
None
)
->
None
:
def
normalize
(
self
,
logger
=
None
)
->
None
:
"""The caller will automatically log if the normalizer succeeds or ends
"""The caller will automatically log if the normalizer succeeds or ends
up with an exception.
up with an exception.
"""
"""
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
m_create
(
EncyclopediaMetadata
)
sec_enc
=
self
.
entry_archive
.
section_metadata
.
m_create
(
EncyclopediaMetadata
)
status_enums
=
EncyclopediaMetadata
.
status
.
type
status_enums
=
EncyclopediaMetadata
.
status
.
type
calc_enums
=
Calculation
.
calculation_type
.
type
calc_enums
=
Calculation
.
calculation_type
.
type
...
@@ -222,7 +222,6 @@ class EncyclopediaNormalizer(Normalizer):
...
@@ -222,7 +222,6 @@ class EncyclopediaNormalizer(Normalizer):
try
:
try
:
super
().
normalize
(
logger
)
super
().
normalize
(
logger
)
# Initialise metainfo structure
# Initialise metainfo structure
material
=
sec_enc
.
m_create
(
Material
)
material
=
sec_enc
.
m_create
(
Material
)
method
=
sec_enc
.
m_create
(
Method
)
method
=
sec_enc
.
m_create
(
Method
)
...
...
nomad/normalizing/encyclopedia/material.py
View file @
8ea11000
...
@@ -35,7 +35,6 @@ from nomad.datamodel.encyclopedia import (
...
@@ -35,7 +35,6 @@ from nomad.datamodel.encyclopedia import (
LatticeParameters
,
LatticeParameters
,
)
)
from
nomad.normalizing.encyclopedia.context
import
Context
from
nomad.normalizing.encyclopedia.context
import
Context
from
nomad.parsing.legacy
import
Backend
from
nomad.metainfo
import
Section
from
nomad.metainfo
import
Section
from
nomad
import
atomutils
from
nomad
import
atomutils
from
nomad.utils
import
hash
from
nomad.utils
import
hash
...
@@ -48,9 +47,9 @@ class MaterialNormalizer():
...
@@ -48,9 +47,9 @@ class MaterialNormalizer():
"""A base class that is used for processing material-related information
"""A base class that is used for processing material-related information
in the Encylopedia.
in the Encylopedia.
"""
"""
def
__init__
(
self
,
backend
:
Backend
,
logger
):
def
__init__
(
self
,
entry_archive
,
logger
):
self
.
backend
=
backend
self
.
logger
=
logger
self
.
logger
=
logger
self
.
entry_archive
=
entry_archive
def
atom_labels
(
self
,
ideal
:
IdealizedStructure
,
std_atoms
:
Atoms
)
->
None
:
def
atom_labels
(
self
,
ideal
:
IdealizedStructure
,
std_atoms
:
Atoms
)
->
None
:
ideal
.
atom_labels
=
std_atoms
.
get_chemical_symbols
()
ideal
.
atom_labels
=
std_atoms
.
get_chemical_symbols
()
...
@@ -372,7 +371,7 @@ class MaterialBulkNormalizer(MaterialNormalizer):
...
@@ -372,7 +371,7 @@ class MaterialBulkNormalizer(MaterialNormalizer):
def
normalize
(
self
,
context
:
Context
)
->
None
:
def
normalize
(
self
,
context
:
Context
)
->
None
:
# Fetch resources
# Fetch resources
sec_system
=
context
.
representative_system
sec_system
=
context
.
representative_system
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
encyclopedia
sec_enc
=
self
.
entry_archive
.
section_metadata
.
encyclopedia
material
=
sec_enc
.
material
material
=
sec_enc
.
material
properties
=
sec_enc
.
properties
properties
=
sec_enc
.
properties
sec_symmetry
=
sec_system
[
"section_symmetry"
][
0
]
sec_symmetry
=
sec_system
[
"section_symmetry"
][
0
]
...
@@ -498,7 +497,7 @@ class Material2DNormalizer(MaterialNormalizer):
...
@@ -498,7 +497,7 @@ class Material2DNormalizer(MaterialNormalizer):
def
normalize
(
self
,
context
:
Context
)
->
None
:
def
normalize
(
self
,
context
:
Context
)
->
None
:
# Fetch resources
# Fetch resources
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
encyclopedia
sec_enc
=
self
.
entry_archive
.
section_metadata
.
encyclopedia
material
=
sec_enc
.
material
material
=
sec_enc
.
material
repr_atoms
=
context
.
representative_system
.
m_cache
[
"representative_atoms"
]
# Temporary value stored by SystemNormalizer
repr_atoms
=
context
.
representative_system
.
m_cache
[
"representative_atoms"
]
# Temporary value stored by SystemNormalizer
symmetry_analyzer
=
self
.
get_symmetry_analyzer
(
repr_atoms
)
symmetry_analyzer
=
self
.
get_symmetry_analyzer
(
repr_atoms
)
...
@@ -716,7 +715,7 @@ class Material1DNormalizer(MaterialNormalizer):
...
@@ -716,7 +715,7 @@ class Material1DNormalizer(MaterialNormalizer):
def
normalize
(
self
,
context
:
Context
)
->
None
:
def
normalize
(
self
,
context
:
Context
)
->
None
:
# Fetch resources
# Fetch resources
sec_system
=
context
.
representative_system
sec_system
=
context
.
representative_system
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
encyclopedia
sec_enc
=
self
.
entry_archive
.
section_metadata
.
encyclopedia
material
=
sec_enc
.
material
material
=
sec_enc
.
material
repr_atoms
=
sec_system
.
m_cache
[
"representative_atoms"
]
# Temporary value stored by SystemNormalizer
repr_atoms
=
sec_system
.
m_cache
[
"representative_atoms"
]
# Temporary value stored by SystemNormalizer
symmetry_analyzer
=
self
.
get_symmetry_analyzer
(
repr_atoms
)
symmetry_analyzer
=
self
.
get_symmetry_analyzer
(
repr_atoms
)
...
...
nomad/normalizing/encyclopedia/method.py
View file @
8ea11000
...
@@ -33,10 +33,10 @@ class MethodNormalizer():
...
@@ -33,10 +33,10 @@ class MethodNormalizer():
"""A base class that is used for processing method related information
"""A base class that is used for processing method related information
in the Encylopedia.
in the Encylopedia.
"""
"""
def
__init__
(
self
,
backend
,
logger
):
def
__init__
(
self
,
entry_archive
,
logger
):
self
.
backend
=
backend
self
.
logger
=
logger
self
.
logger
=
logger
self
.
section_run
=
backend
.
entry_archive
.
section_run
[
0
]
self
.
entry_archive
=
entry_archive
self
.
section_run
=
entry_archive
.
section_run
[
0
]
def
method_id
(
self
,
method
:
Method
,
settings_basis_set
:
RestrictedDict
,
repr_method
:
Section
):
def
method_id
(
self
,
method
:
Method
,
settings_basis_set
:
RestrictedDict
,
repr_method
:
Section
):
method_dict
=
RestrictedDict
(
method_dict
=
RestrictedDict
(
...
@@ -76,7 +76,7 @@ class MethodNormalizer():
...
@@ -76,7 +76,7 @@ class MethodNormalizer():
)
)
# Only calculations from the same upload are grouped
# Only calculations from the same upload are grouped
eos_dict
[
'upload_id'
]
=
self
.
backend
.
entry_archive
.
section_metadata
.
upload_id
eos_dict
[
'upload_id'
]
=
self
.
entry_archive
.
section_metadata
.
upload_id
# Method
# Method
eos_dict
[
"method_id"
]
=
method
.
method_id
eos_dict
[
"method_id"
]
=
method
.
method_id
...
@@ -106,11 +106,11 @@ class MethodNormalizer():
...
@@ -106,11 +106,11 @@ class MethodNormalizer():
)
)
# Only calculations from the same upload are grouped
# Only calculations from the same upload are grouped
param_dict
[
'upload_id'
]
=
self
.
backend
.
entry_archive
.
section_metadata
.
upload_id
param_dict
[
'upload_id'
]
=
self
.
entry_archive
.
section_metadata
.
upload_id
# The same code and functional type is required
# The same code and functional type is required
param_dict
[
'program_name'
]
=
self
.
backend
[
"
program_name
"
]
param_dict
[
'program_name'
]
=
self
.
section_run
.
program_name
param_dict
[
'program_version'
]
=
self
.
backend
[
"
program_version
"
]
param_dict
[
'program_version'
]
=
self
.
section_run
.
program_version
# Get a string representation of the geometry. It is included as the
# Get a string representation of the geometry. It is included as the
# geometry should remain the same during parameter variation. By simply
# geometry should remain the same during parameter variation. By simply
...
@@ -166,7 +166,7 @@ class MethodDFTNormalizer(MethodNormalizer):
...
@@ -166,7 +166,7 @@ class MethodDFTNormalizer(MethodNormalizer):
"""
"""
def
core_electron_treatment
(
self
,
method
:
Method
)
->
None
:
def
core_electron_treatment
(
self
,
method
:
Method
)
->
None
:
treatment
=
config
.
services
.
unavailable_value
treatment
=
config
.
services
.
unavailable_value
code_name
=
self
.
backend
[
"
program_name
"
]
code_name
=
self
.
section_run
.
program_name
if
code_name
is
not
None
:
if
code_name
is
not
None
:
core_electron_treatments
=
{
core_electron_treatments
=
{
'VASP'
:
'pseudopotential'
,
'VASP'
:
'pseudopotential'
,
...
@@ -382,10 +382,10 @@ class MethodDFTNormalizer(MethodNormalizer):
...
@@ -382,10 +382,10 @@ class MethodDFTNormalizer(MethodNormalizer):
# Fetch resources
# Fetch resources
repr_method
=
context
.
representative_method
repr_method
=
context
.
representative_method
repr_system
=
context
.
representative_system
repr_system
=
context
.
representative_system
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
encyclopedia
sec_enc
=
self
.
entry_archive
.
section_metadata
.
encyclopedia
method
=
sec_enc
.
method
method
=
sec_enc
.
method
material
=
sec_enc
.
material
material
=
sec_enc
.
material
settings_basis_set
=
get_basis_set
(
context
,
self
.
backend
,
self
.
logger
)
settings_basis_set
=
get_basis_set
(
context
,
self
.
entry_archive
,
self
.
logger
)
# Fill metainfo
# Fill metainfo
self
.
core_electron_treatment
(
method
)
self
.
core_electron_treatment
(
method
)
...
@@ -421,7 +421,7 @@ class MethodGWNormalizer(MethodDFTNormalizer):
...
@@ -421,7 +421,7 @@ class MethodGWNormalizer(MethodDFTNormalizer):
def
normalize
(
self
,
context
:
Context
)
->
None
:
def
normalize
(
self
,
context
:
Context
)
->
None
:
# Fetch resources
# Fetch resources
repr_method
=
context
.
representative_method
repr_method
=
context
.
representative_method
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
encyclopedia
sec_enc
=
self
.
entry_archive
.
section_metadata
.
encyclopedia
method
=
sec_enc
.
method
method
=
sec_enc
.
method
# Fill metainfo
# Fill metainfo
...
...
nomad/normalizing/encyclopedia/properties.py
View file @
8ea11000
...
@@ -17,7 +17,6 @@ from nomad.datamodel.encyclopedia import (
...
@@ -17,7 +17,6 @@ from nomad.datamodel.encyclopedia import (
Properties
,
Properties
,
Energies
,
Energies
,
)
)
from
nomad.parsing.legacy
import
Backend
from
nomad.metainfo
import
Section
from
nomad.metainfo
import
Section
from
nomad.normalizing.encyclopedia.context
import
Context
from
nomad.normalizing.encyclopedia.context
import
Context
...
@@ -26,8 +25,8 @@ class PropertiesNormalizer():
...
@@ -26,8 +25,8 @@ class PropertiesNormalizer():
"""A base class that is used for processing calculated quantities that
"""A base class that is used for processing calculated quantities that
should be extracted to Encyclopedia.
should be extracted to Encyclopedia.
"""
"""
def
__init__
(
self
,
backend
:
Backend
,
logger
):
def
__init__
(
self
,
entry_archive
,
logger
):
self
.
backend
=
backend
self
.
entry_archive
=
entry_archive
self
.
logger
=
logger
self
.
logger
=
logger
def
electronic_band_structure
(
self
,
properties
:
Properties
,
calc_type
:
str
,
material_type
:
str
,
context
:
Context
,
sec_system
:
Section
)
->
None
:
def
electronic_band_structure
(
self
,
properties
:
Properties
,
calc_type
:
str
,
material_type
:
str
,
context
:
Context
,
sec_system
:
Section
)
->
None
:
...
@@ -131,7 +130,7 @@ class PropertiesNormalizer():
...
@@ -131,7 +130,7 @@ class PropertiesNormalizer():
"""
"""
try
:
try
:
resolved_section
=
None
resolved_section
=
None
frame_sequences
=
self
.
backend
.
entry_archive
.
section_run
[
0
].
section_frame_sequence
frame_sequences
=
self
.
entry_archive
.
section_run
[
0
].
section_frame_sequence
for
frame_sequence
in
reversed
(
frame_sequences
):
for
frame_sequence
in
reversed
(
frame_sequences
):
thermodynamical_props
=
frame_sequence
.
section_thermodynamical_properties
thermodynamical_props
=
frame_sequence
.
section_thermodynamical_properties
for
thermodynamical_prop
in
thermodynamical_props
:
for
thermodynamical_prop
in
thermodynamical_props
:
...
@@ -224,7 +223,7 @@ class PropertiesNormalizer():
...
@@ -224,7 +223,7 @@ class PropertiesNormalizer():
return
return
# Fetch resources
# Fetch resources
sec_enc
=
self
.
backend
.
entry_archive
.
section_metadata
.
encyclopedia
sec_enc
=
self
.
entry_archive
.
section_metadata
.
encyclopedia
properties
=
sec_enc
.
properties
properties
=
sec_enc
.
properties
calc_type
=
context
.
calc_type
calc_type
=
context
.
calc_type
material_type
=
context
.
material_type
material_type
=
context
.
material_type
...
...
nomad/normalizing/optimade.py
View file @
8ea11000
...
@@ -12,17 +12,17 @@
...
@@ -12,17 +12,17 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
typing
import
Any
,
Dict
,
cast
from
typing
import
Any
,
Dict
import
numpy
as
np
import
numpy
as
np
import
re
import
re
import
ase.data
import
ase.data
from
string
import
ascii_uppercase
from
string
import
ascii_uppercase
import
pint.quantity
import
pint.quantity
from
nomad.parsing.legacy
import
Backend
from
nomad.normalizing.normalizer
import
SystemBasedNormalizer
from
nomad.normalizing.normalizer
import
SystemBasedNormalizer
from
nomad.units
import
ureg
from
nomad.units
import
ureg
from
nomad.datamodel
import
OptimadeEntry
,
Species
,
DFTMetadata
,
EntryMetadata
from
nomad.datamodel
import
OptimadeEntry
,
Species
,
DFTMetadata
,
EntryMetadata
from
nomad.datamodel.metainfo.public
import
section_system
species_re
=
re
.
compile
(
r
'^([A-Z][a-z]?)(\d*)$'
)
species_re
=
re
.
compile
(
r
'^([A-Z][a-z]?)(\d*)$'
)
...
@@ -43,16 +43,15 @@ class OptimadeNormalizer(SystemBasedNormalizer):
...
@@ -43,16 +43,15 @@ class OptimadeNormalizer(SystemBasedNormalizer):
Normalizes geometry, classifies, system_type, and runs symmetry analysis.
Normalizes geometry, classifies, system_type, and runs symmetry analysis.
'''
'''
backend
=
cast
(
Backend
,
self
.
_backend
)
if
self
.
entry_archive
.
section_metadata
is
None
:
if
backend
.
entry_archive
.
section_metadata
is
None
:
self
.
entry_archive
.
m_create
(
EntryMetadata
)
backend
.
entry_archive
.
m_create
(
EntryMetadata
)
if
self
.
entry_archive
.
section_metadata
.
dft
is
None
:
if
backend
.
entry_archive
.
section_metadata
.
dft
is
None
:
self
.
entry_archive
.
section_metadata
.
m_create
(
DFTMetadata
)
backend
.
entry_archive
.
section_metadata
.
m_create
(
DFTMetadata
)
optimade
=
self
.
entry_archive
.
section_metadata
.
dft
.
m_create
(
OptimadeEntry
)
optimade
=
backend
.
entry_archive
.
section_metadata
.
dft
.
m_create
(
OptimadeEntry
)
def
get_value
(
key
:
str
,
default
:
Any
=
None
,
numpy
:
bool
=
False
,
unit
=
None
)
->
Any
:
def
get_value
(
quantity_def
,
default
:
Any
=
None
,
numpy
:
bool
=
False
,
unit
=
None
)
->
Any
:
try
:
try
:
value
=
self
.
_backend
.
get_value
(
key
,
in
de
x
)
value
=
self
.
section_run
.
section_system
[
-
1
].
m_get
(
quantity_
de
f
)
if
type
(
value
)
==
np
.
ndarray
and
not
numpy
:
if
type
(
value
)
==
np
.
ndarray
and
not
numpy
:
return
value
.
tolist
()
return
value
.
tolist
()
if
isinstance
(
value
,
list
)
and
numpy
:
if
isinstance
(
value
,
list
)
and
numpy
:
...
@@ -70,7 +69,7 @@ class OptimadeNormalizer(SystemBasedNormalizer):
...
@@ -70,7 +69,7 @@ class OptimadeNormalizer(SystemBasedNormalizer):
from
nomad.normalizing.system
import
normalized_atom_labels
from
nomad.normalizing.system
import
normalized_atom_labels
nomad_species
=
get_value
(
'
atom_labels
'
)
nomad_species
=
get_value
(
section_system
.
atom_labels
)
# elements
# elements
atoms
=
normalized_atom_labels
(
nomad_species
)
atoms
=
normalized_atom_labels
(
nomad_species
)
...
@@ -89,8 +88,8 @@ class OptimadeNormalizer(SystemBasedNormalizer):
...
@@ -89,8 +88,8 @@ class OptimadeNormalizer(SystemBasedNormalizer):
for
element
in
optimade
.
elements
]
for
element
in
optimade
.
elements
]
# formulas
# formulas
optimade
.
chemical_formula_reduced
=
get_value
(
'
chemical_composition_reduced
'
)
optimade
.
chemical_formula_reduced
=
get_value
(
section_system
.
chemical_composition_reduced
)
optimade
.
chemical_formula_hill
=
get_value
(
'
chemical_composition_bulk_reduced
'
)
optimade
.
chemical_formula_hill
=
get_value
(
section_system
.
chemical_composition_bulk_reduced
)
optimade
.
chemical_formula_descriptive
=
optimade
.
chemical_formula_hill
optimade
.
chemical_formula_descriptive
=
optimade
.
chemical_formula_hill
optimade
.
chemical_formula_anonymous
=
''
optimade
.
chemical_formula_anonymous
=
''
for
i
in
range
(
len
(
optimade
.
elements
)):
for
i
in
range
(
len
(
optimade
.
elements
)):
...
@@ -102,11 +101,11 @@ class OptimadeNormalizer(SystemBasedNormalizer):
...
@@ -102,11 +101,11 @@ class OptimadeNormalizer(SystemBasedNormalizer):
# sites
# sites
optimade
.
nsites
=
len
(
nomad_species
)
optimade
.
nsites
=
len
(
nomad_species
)
optimade
.
species_at_sites
=
nomad_species
optimade
.
species_at_sites
=
nomad_species
optimade
.
lattice_vectors
=
get_value
(
'
lattice_vectors
'
,
numpy
=
True
,
unit
=
ureg
.
m
)
optimade
.
lattice_vectors
=
get_value
(
section_system
.
lattice_vectors
,
numpy
=
True
,
unit
=
ureg
.
m
)
optimade
.
cartesian_site_positions
=
get_value
(
'
atom_positions
'
,
numpy
=
True
,
unit
=
ureg
.
m
)
optimade
.
cartesian_site_positions
=
get_value
(
section_system
.
atom_positions
,
numpy
=
True
,
unit
=
ureg
.
m
)
optimade
.
dimension_types
=
[
optimade
.
dimension_types
=
[
1
if
value
else
0
1
if
value
else
0
for
value
in
get_value
(
'
configuration_periodic_dimensions
'
)]
for
value
in
get_value
(
section_system
.
configuration_periodic_dimensions
)]
# species
# species
for
species_label
in
set
(
nomad_species
):
for
species_label
in
set
(
nomad_species
):
...
...
nomad/normalizing/system.py
View file @
8ea11000
...
@@ -24,6 +24,9 @@ from matid.classifications import Class0D, Atom, Class1D, Material2D, Surface, C
...
@@ -24,6 +24,9 @@ from matid.classifications import Class0D, Atom, Class1D, Material2D, Surface, C
from
nomad
import
atomutils
,
archive
from
nomad
import
atomutils
,
archive
from
nomad
import
utils
,
config
from
nomad
import
utils
,
config
from
nomad.datamodel.metainfo.public
import
section_symmetry
,
section_std_system
,
\
section_primitive_system
,
section_original_system
,
section_springer_material
,
\
section_prototype
,
section_system
from
.normalizer
import
SystemBasedNormalizer
from
.normalizer
import
SystemBasedNormalizer
...
@@ -89,10 +92,13 @@ class SystemNormalizer(SystemBasedNormalizer):
...
@@ -89,10 +92,13 @@ class SystemNormalizer(SystemBasedNormalizer):
Returns: True, iff the normalization was successful
Returns: True, iff the normalization was successful
'''
'''
if
self
.
section_run
is
None
:
self
.
logger
.
error
(
'section_run is not present.'
)
return
False
def
get_value
(
key
:
str
,
default
:
Any
=
None
,
numpy
:
bool
=
True
)
->
Any
:
def
get_value
(
quantity_def
,
default
:
Any
=
None
,
numpy
:
bool
=
True
)
->
Any
:
try
:
try
:
value
=
s
elf
.
_backend
.
get_value
(
key
,
system
.
m_parent_in
de
x
)
value
=
s
ystem
.
m_get
(
quantity_
de
f
)
if
not
numpy
and
type
(
value
).
__module__
==
np
.
__name__
:
if
not
numpy
and
type
(
value
).
__module__
==
np
.
__name__
:
value
=
value
.
tolist
()
value
=
value
.
tolist
()
...
@@ -103,18 +109,15 @@ class SystemNormalizer(SystemBasedNormalizer):
...
@@ -103,18 +109,15 @@ class SystemNormalizer(SystemBasedNormalizer):
except
(
KeyError
,
IndexError
):
except
(
KeyError
,
IndexError
):
return
default
return
default
def
set_value
(
key
:
str
,
value
:
Any
):
self
.
_backend
.
addValue
(
key
,
value
)
if
is_representative
:
if
is_representative
:
s
elf
.
_backend
.
addValue
(
'
is_representative
'
,
is_representative
)
s
ystem
.
is_representative
=
is_representative
# analyze atoms labels
# analyze atoms labels
atom_labels
=
get_value
(
'
atom_labels
'
,
numpy
=
False
)
atom_labels
=
get_value
(
section_system
.
atom_labels
,
numpy
=
False
)
if
atom_labels
is
not
None
:
if
atom_labels
is
not
None
:
atom_labels
=
normalized_atom_labels
(
atom_labels
)
atom_labels
=
normalized_atom_labels
(
atom_labels
)
atom_species
=
get_value
(
'
atom_species
'
,
numpy
=
False
)
atom_species
=
get_value
(
section_system
.
atom_species
,
numpy
=
False
)
if
atom_labels
is
None
and
atom_species
is
None
:
if
atom_labels
is
None
and
atom_species
is
None
:
self
.
logger
.
warn
(
'system has neither atom species nor labels'
)
self
.
logger
.
warn
(
'system has neither atom species nor labels'
)
return
False
return
False
...
@@ -127,7 +130,7 @@ class SystemNormalizer(SystemBasedNormalizer):
...
@@ -127,7 +130,7 @@ class SystemNormalizer(SystemBasedNormalizer):
self
.
logger
.
error
(
'system has atom species that are out of range'
)
self
.
logger
.
error
(
'system has atom species that are out of range'
)
return
False
return
False
s
elf
.
_backend
.
addArrayValues
(
'
atom_labels
'
,
atom_labels
)
s
ystem
.
atom_labels
=
atom_labels
# At this point we should have atom labels.
# At this point we should have atom labels.
try
:
try
:
...
@@ -144,7 +147,7 @@ class SystemNormalizer(SystemBasedNormalizer):
...
@@ -144,7 +147,7 @@ class SystemNormalizer(SystemBasedNormalizer):
if
atom_species
is
None
:
if
atom_species
is
None
:
atom_species
=
atoms
.
get_atomic_numbers
().
tolist
()
atom_species
=
atoms
.
get_atomic_numbers
().
tolist
()
s
elf
.
_backend
.
addArrayValues
(
'
atom_species
'
,
atom_species
)
s
ystem
.
atom_species
=
atom_species
else
:
else
:
if
not
isinstance
(
atom_species
,
list
):
if
not
isinstance
(
atom_species
,
list
):
atom_species
=
[
atom_species
]
atom_species
=
[
atom_species
]
...
@@ -153,14 +156,14 @@ class SystemNormalizer(SystemBasedNormalizer):
...
@@ -153,14 +156,14 @@ class SystemNormalizer(SystemBasedNormalizer):
'atom species do not match labels'
,
'atom species do not match labels'
,
atom_labels
=
atom_labels
[:
10
],
atom_species
=
atom_species
[:
10
])
atom_labels
=
atom_labels
[:
10
],
atom_species
=
atom_species
[:
10
])
atom_species
=
atoms
.
get_atomic_numbers
().
tolist
()
atom_species
=
atoms
.
get_atomic_numbers
().
tolist
()
s
et_value
(
'
atom_species
'
,
atom_species
)
s
ystem
.
atom_species
=
atom_species
# periodic boundary conditions
# periodic boundary conditions
pbc
=
get_value
(
'
configuration_periodic_dimensions
'
,
numpy
=
False
)
pbc
=
get_value
(
section_system
.
configuration_periodic_dimensions
,
numpy
=
False
)
if
pbc
is
None
:
if
pbc
is
None
:
pbc
=
[
False
,
False
,
False
]
pbc
=
[
False
,
False
,
False
]