Skip to content
Snippets Groups Projects
Commit 6abd956d authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Realized that in base64 encoding the default 28 chars will be enough space for anything.

parent e1b6b2a8
No related branches found
No related tags found
4 merge requests!115V0.8.0 beta,!113V0.8.0,!103Merging Encyclopedia functionality with v0.8.0,!102First version of EncyclopediaNormalizer
...@@ -14,9 +14,8 @@ class Material(MSection): ...@@ -14,9 +14,8 @@ class Material(MSection):
material_hash = Quantity( material_hash = Quantity(
type=str, type=str,
description=""" description="""
A unique material identifier. For crystals the hash A fixed length, unique material identifier in the form of a hash
identifier is constructed from formula, space group and digest.
wyckoff_position_population.
""" """
) )
system_type = Quantity( system_type = Quantity(
...@@ -268,6 +267,30 @@ class Calculation(MSection): ...@@ -268,6 +267,30 @@ class Calculation(MSection):
Mass density of the material based on the structural information. Mass density of the material based on the structural information.
""" """
) )
method_hash = Quantity(
type=str,
description="""
A fixed length, unique method identifier in the form of a hash
digest.
"""
)
group_eos_hash = Quantity(
type=str,
description="""
A fixed length, unique identifier for equation-of-state calculations.
Only calculations wihtin the same upload will be grouped under the same
hash.
"""
)
group_parametervariation_hash = Quantity(
type=str,
description="""
A fixed length, unique identifier for calculations where structure is
identical but the used computational parameters are varied. Only
calculations within the same upload will be grouped under the same
hash.
"""
)
run_type = Quantity( run_type = Quantity(
type=MEnum( type=MEnum(
single_point="single point", single_point="single point",
......
...@@ -277,7 +277,7 @@ class Structure(): ...@@ -277,7 +277,7 @@ class Structure():
# Create and store hash based on SHA512 # Create and store hash based on SHA512
norm_hash_string = structure.get_symmetry_string(space_group_number, wyckoff_sets) norm_hash_string = structure.get_symmetry_string(space_group_number, wyckoff_sets)
material.material_hash = hash(norm_hash_string, length=128) material.material_hash = hash(norm_hash_string)
def number_of_atoms(self, material: Material, std_atoms: ase.Atoms) -> None: def number_of_atoms(self, material: Material, std_atoms: ase.Atoms) -> None:
material.number_of_atoms = len(std_atoms) material.number_of_atoms = len(std_atoms)
...@@ -705,7 +705,7 @@ class Structure1D(Structure): ...@@ -705,7 +705,7 @@ class Structure1D(Structure):
id_strings.append(formula) id_strings.append(formula)
id_strings.append(fingerprint) id_strings.append(fingerprint)
hash_seed = ", ".join(id_strings) hash_seed = ", ".join(id_strings)
hash_val = hash(hash_seed, length=128) hash_val = hash(hash_seed)
material.material_hash = hash_val material.material_hash = hash_val
def cell_normalized(self, material: Material, std_atoms: ase.Atoms) -> None: def cell_normalized(self, material: Material, std_atoms: ase.Atoms) -> None:
...@@ -948,7 +948,7 @@ class Method(): ...@@ -948,7 +948,7 @@ class Method():
group_eos_hash = self.group_dict_to_hash('group_eos_hash', hash_dict) group_eos_hash = self.group_dict_to_hash('group_eos_hash', hash_dict)
calculation.group_eos_hash = group_eos_hash calculation.group_eos_hash = group_eos_hash
def group_parametervariation_hash(self): def group_parametervariation_hash(self, calculation: Calculation):
# Create ordered dictionary with the values. Order is important for # Create ordered dictionary with the values. Order is important for
# consistent hashing. # consistent hashing.
hash_dict: OrderedDict = OrderedDict() hash_dict: OrderedDict = OrderedDict()
...@@ -960,7 +960,7 @@ class Method(): ...@@ -960,7 +960,7 @@ class Method():
# Form a hash from the dictionary # Form a hash from the dictionary
group_eos_hash = self.group_dict_to_hash('group_eos_hash', hash_dict) group_eos_hash = self.group_dict_to_hash('group_eos_hash', hash_dict)
calculation.group_eos_hash = group_eos_hash calculation.group_parametervariation_hash = group_eos_hash
def group_e_min(self) -> None: def group_e_min(self) -> None:
pass pass
...@@ -1006,15 +1006,15 @@ class Method(): ...@@ -1006,15 +1006,15 @@ class Method():
@abstractmethod @abstractmethod
def method_hash_dict(self): def method_hash_dict(self):
return OrderedDict(); return OrderedDict()
@abstractmethod @abstractmethod
def group_eos_hash_dict(self): def group_eos_hash_dict(self):
return OrderedDict(); return OrderedDict()
@abstractmethod @abstractmethod
def group_parametervariation_hash_dict(self): def group_parametervariation_hash_dict(self):
return OrderedDict(); return OrderedDict()
def group_dict_to_hash(self, name, src_dict: OrderedDict): def group_dict_to_hash(self, name, src_dict: OrderedDict):
"""Given a dictionary of computational settings, this function forms a """Given a dictionary of computational settings, this function forms a
......
...@@ -73,7 +73,8 @@ def decode_handle_id(handle_str: str): ...@@ -73,7 +73,8 @@ def decode_handle_id(handle_str: str):
def hash(*args, length: int = default_hash_len) -> str: def hash(*args, length: int = default_hash_len) -> str:
""" Creates a websave hash of the given length based on the repr of the given arguments. """ """Creates a websave hash of the given length based on the repr of the given arguments.
"""
hash = hashlib.sha512() hash = hashlib.sha512()
for arg in args: for arg in args:
hash.update(str(arg).encode('utf-8')) hash.update(str(arg).encode('utf-8'))
...@@ -82,7 +83,8 @@ def hash(*args, length: int = default_hash_len) -> str: ...@@ -82,7 +83,8 @@ def hash(*args, length: int = default_hash_len) -> str:
def make_websave(hash, length: int = default_hash_len) -> str: def make_websave(hash, length: int = default_hash_len) -> str:
""" Creates a websave string for a hashlib hash object. """ """Creates a websave string for a hashlib hash object.
"""
if length > 0: if length > 0:
return base64.b64encode(hash.digest(), altchars=b'-_')[:length].decode('utf-8') return base64.b64encode(hash.digest(), altchars=b'-_')[:length].decode('utf-8')
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment