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
......@@ -14,9 +14,8 @@ class Material(MSection):
material_hash = Quantity(
type=str,
description="""
A unique material identifier. For crystals the hash
identifier is constructed from formula, space group and
wyckoff_position_population.
A fixed length, unique material identifier in the form of a hash
digest.
"""
)
system_type = Quantity(
......@@ -268,6 +267,30 @@ class Calculation(MSection):
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(
type=MEnum(
single_point="single point",
......
......@@ -277,7 +277,7 @@ class Structure():
# Create and store hash based on SHA512
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:
material.number_of_atoms = len(std_atoms)
......@@ -705,7 +705,7 @@ class Structure1D(Structure):
id_strings.append(formula)
id_strings.append(fingerprint)
hash_seed = ", ".join(id_strings)
hash_val = hash(hash_seed, length=128)
hash_val = hash(hash_seed)
material.material_hash = hash_val
def cell_normalized(self, material: Material, std_atoms: ase.Atoms) -> None:
......@@ -948,7 +948,7 @@ class Method():
group_eos_hash = self.group_dict_to_hash('group_eos_hash', hash_dict)
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
# consistent hashing.
hash_dict: OrderedDict = OrderedDict()
......@@ -960,7 +960,7 @@ class Method():
# Form a hash from the dictionary
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:
pass
......@@ -1006,15 +1006,15 @@ class Method():
@abstractmethod
def method_hash_dict(self):
return OrderedDict();
return OrderedDict()
@abstractmethod
def group_eos_hash_dict(self):
return OrderedDict();
return OrderedDict()
@abstractmethod
def group_parametervariation_hash_dict(self):
return OrderedDict();
return OrderedDict()
def group_dict_to_hash(self, name, src_dict: OrderedDict):
"""Given a dictionary of computational settings, this function forms a
......
......@@ -73,7 +73,8 @@ def decode_handle_id(handle_str: 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()
for arg in args:
hash.update(str(arg).encode('utf-8'))
......@@ -82,7 +83,8 @@ def hash(*args, 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:
return base64.b64encode(hash.digest(), altchars=b'-_')[:length].decode('utf-8')
else:
......
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