Commit 63df2a63 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Fixed attribute access.

parent 30ec7560
Pipeline #76180 failed with stages
in 31 minutes and 4 seconds
...@@ -798,6 +798,7 @@ statistics_result = api.model("statistics_result", { ...@@ -798,6 +798,7 @@ statistics_result = api.model("statistics_result", {
"alpha": fields.Nested(statistics), "alpha": fields.Nested(statistics),
"beta": fields.Nested(statistics), "beta": fields.Nested(statistics),
"gamma": fields.Nested(statistics), "gamma": fields.Nested(statistics),
"band_gap": fields.Nested(statistics),
}) })
property_map = { property_map = {
"cell_volume": "encyclopedia.material.idealized_structure.cell_volume", "cell_volume": "encyclopedia.material.idealized_structure.cell_volume",
...@@ -809,6 +810,7 @@ property_map = { ...@@ -809,6 +810,7 @@ property_map = {
"alpha": "encyclopedia.material.idealized_structure.lattice_parameters.alpha", "alpha": "encyclopedia.material.idealized_structure.lattice_parameters.alpha",
"beta": "encyclopedia.material.idealized_structure.lattice_parameters.beta", "beta": "encyclopedia.material.idealized_structure.lattice_parameters.beta",
"gamma": "encyclopedia.material.idealized_structure.lattice_parameters.gamma", "gamma": "encyclopedia.material.idealized_structure.lattice_parameters.gamma",
"band_gap": "encyclopedia.properties.band_gap",
} }
...@@ -825,6 +827,7 @@ class EncStatisticsResource(Resource): ...@@ -825,6 +827,7 @@ class EncStatisticsResource(Resource):
calculations. calculations.
""" """
# Get query parameters as json # Get query parameters as json
print(request.get_json())
try: try:
data = marshal(request.get_json(), statistics_query) data = marshal(request.get_json(), statistics_query)
except Exception as e: except Exception as e:
...@@ -1004,6 +1007,9 @@ calculation_property_map = { ...@@ -1004,6 +1007,9 @@ calculation_property_map = {
"cell_volume": { "cell_volume": {
"es_source": "encyclopedia.material.idealized_structure.cell_volume" "es_source": "encyclopedia.material.idealized_structure.cell_volume"
}, },
"band_gap": {
"es_source": "encyclopedia.properties.band_gap"
},
"electronic_band_structure": { "electronic_band_structure": {
"es_source": "encyclopedia.properties.electronic_band_structure" "es_source": "encyclopedia.properties.electronic_band_structure"
}, },
...@@ -1023,6 +1029,15 @@ energies = api.model("energies", { ...@@ -1023,6 +1029,15 @@ energies = api.model("energies", {
"energy_total_T0": fields.Float, "energy_total_T0": fields.Float,
"energy_free": fields.Float, "energy_free": fields.Float,
}) })
electronic_band_structure = api.model("electronic_band_structure", {
"reciprocal_cell": fields.List(fields.List(fields.Float)),
"brillouin_zone": fields.Raw,
"section_k_band_segment": fields.Raw,
})
electronic_dos = api.model("electronic_dos", {
"dos_energies": fields.List(fields.Float),
"dos_values": fields.List(fields.Float),
})
calculation_property_result = api.model("calculation_query", { calculation_property_result = api.model("calculation_query", {
"lattice_parameters": fields.Nested(lattice_parameters), "lattice_parameters": fields.Nested(lattice_parameters),
"energies": fields.Nested(energies), "energies": fields.Nested(energies),
...@@ -1030,8 +1045,9 @@ calculation_property_result = api.model("calculation_query", { ...@@ -1030,8 +1045,9 @@ calculation_property_result = api.model("calculation_query", {
"atomic_density": fields.Float, "atomic_density": fields.Float,
"cell_volume": fields.Float, "cell_volume": fields.Float,
"wyckoff_sets": fields.Nested(wyckoff_set_result), "wyckoff_sets": fields.Nested(wyckoff_set_result),
# "electronic_band_structure": fields.Nested(electronic_band_structure), "band_gap": fields.Float(wyckoff_set_result),
# "electronic_dos": fields.Nested(electronic_dos), "electronic_band_structure": fields.Nested(electronic_band_structure),
"electronic_dos": fields.Nested(electronic_dos),
}) })
...@@ -1104,9 +1120,13 @@ class EncCalculationResource(Resource): ...@@ -1104,9 +1120,13 @@ class EncCalculationResource(Resource):
# Add references that are to be read from the archive # Add references that are to be read from the archive
for ref in references: for ref in references:
arch_path = response[0] arch_path = response[0]
for attr in es_properties[ref].split("."): try:
arch_path = arch_path[attr] for attr in es_properties[ref].split("."):
arch_properties[ref] = arch_path arch_path = arch_path[attr]
except KeyError:
pass
else:
arch_properties[ref] = arch_path
del es_properties[ref] del es_properties[ref]
# If any of the requested properties require data from the Archive, the # If any of the requested properties require data from the Archive, the
...@@ -1129,8 +1149,12 @@ class EncCalculationResource(Resource): ...@@ -1129,8 +1149,12 @@ class EncCalculationResource(Resource):
# DOS results are simplified # DOS results are simplified
if key == "electronic_dos": if key == "electronic_dos":
del value["dos_energies"] if "dos_energies_normalized" in value:
del value["dos_values"] value["dos_energies"] = value["dos_energies_normalized"]
del value["dos_energies_normalized"]
if "dos_values_normalized" in value:
value["dos_values"] = value["dos_values_normalized"]
del value["dos_values_normalized"]
del value["dos_integrated_values"] del value["dos_integrated_values"]
del value["dos_fermi_energy"] del value["dos_fermi_energy"]
...@@ -1139,11 +1163,15 @@ class EncCalculationResource(Resource): ...@@ -1139,11 +1163,15 @@ class EncCalculationResource(Resource):
# Add results from ES # Add results from ES
for prop, es_source in es_properties.items(): for prop, es_source in es_properties.items():
value = response[0] value = response[0]
for attr in es_source.split("."): try:
value = value[attr] for attr in es_source.split("."):
if isinstance(value, AttrDict): value = value[attr]
value = value.to_dict() except KeyError:
result[prop] = value pass
else:
if isinstance(value, AttrDict):
value = value.to_dict()
result[prop] = value
return result, 200 return result, 200
......
...@@ -451,12 +451,12 @@ def test_hashes_exciting(hash_exciting): ...@@ -451,12 +451,12 @@ def test_hashes_exciting(hash_exciting):
from exciting. from exciting.
""" """
enc = hash_exciting.entry_archive.section_metadata.encyclopedia enc = hash_exciting.entry_archive.section_metadata.encyclopedia
method_hash = enc.method.method_hash method_id = enc.method.method_id
group_eos_hash = enc.method.group_eos_hash group_eos_id = enc.method.group_eos_id
group_parametervariation_hash = enc.method.group_parametervariation_hash group_parametervariation_id = enc.method.group_parametervariation_id
assert method_hash is not None assert method_id is not None
assert group_eos_hash is not None assert group_eos_id is not None
assert group_parametervariation_hash is not None assert group_parametervariation_id is not None
def test_hashes_undefined(hash_vasp): def test_hashes_undefined(hash_vasp):
...@@ -464,14 +464,14 @@ def test_hashes_undefined(hash_vasp): ...@@ -464,14 +464,14 @@ def test_hashes_undefined(hash_vasp):
determined at a sufficient accuracy. determined at a sufficient accuracy.
""" """
enc = hash_vasp.entry_archive.section_metadata.encyclopedia enc = hash_vasp.entry_archive.section_metadata.encyclopedia
method_hash = enc.method.method_hash method_id = enc.method.method_id
group_eos_hash = enc.method.group_eos_hash group_eos_id = enc.method.group_eos_id
# If the method cannot be determined accurately, the method hash and group # If the method cannot be determined accurately, the method hash and group
# hash cannot be set. Parametervariation has may still be valid, as it does # hash cannot be set. Parametervariation has may still be valid, as it does
# not really need the method to be accurately defined. # not really need the method to be accurately defined.
assert method_hash is None assert method_id is None
assert group_eos_hash is None assert group_eos_id is None
def test_dos(dos_unpolarized_vasp, dos_polarized_vasp): def test_dos(dos_unpolarized_vasp, dos_polarized_vasp):
......
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