Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixing get_kinds, still not test. #34

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/aiida_atomistic/data/structure/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ def get_kinds(self, kind_tags=[], exclude=["weight"], custom_thr={}, ready_for_u
]

kinds_dictionary["index"] = kind_numeration
kinds_dictionary["symbol"] = symbols
kinds_dictionary["position"] = self.get_site_property("position")
kinds_dictionary["symbol"] = symbols.tolist()
kinds_dictionary["position"] = self.get_site_property("position").tolist()

# Step 4: check on the kind_tags consistency with the properties value.
if check_kinds and not np.array_equal(check_array, array_tags):
Expand All @@ -717,8 +717,10 @@ def get_kinds(self, kind_tags=[], exclude=["weight"], custom_thr={}, ready_for_u
for index_kind in kinds_dictionary["index"]:
dict_site = {}
for k,v in kinds_dictionary.items():
if k != "index":
if k not in ["symbol","position","index"]:
dict_site[k] = v[index_kind].tolist() if isinstance(v[index_kind], np.ndarray) else v[index_kind]
for value in ["symbol","position"]:
dict_site[value] = kinds_dictionary[value].pop()
new_sites.append(dict_site)
return new_sites

Expand Down Expand Up @@ -1410,7 +1412,9 @@ def get_global_properties(self,):
# for then easy query
global_prop_dict = {}
for prop in self.get_property_names(domain="site"):
global_prop_dict[prop+'s'] = self.get_site_property(prop)
name = prop + "s"
name = name.replace("sss", "sses")
global_prop_dict[name] = self.get_site_property(prop)
#setattr(self, prop+'s', property(lambda self: getattr(self, prop)))

global_prop_dict['volume'] = self.get_cell_volume()
Expand Down
10 changes: 9 additions & 1 deletion tests/data/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def test_to_dict_method(example_structure_dict):

returned_dict = structure.to_dict()

for derived_property in structure.get_global_properties().keys():
returned_dict.pop(derived_property, None)

assert (
returned_dict == example_structure_dict
), f"The dictionary returned by the method, {returned_dict}, \
Expand Down Expand Up @@ -133,7 +136,12 @@ def test_to_be_factorized():
# check StructureData and StructureDataMutable give the same properties.
# in this way I check that it works well.
m.set_pbc([True, True, True])
assert s.to_dict() == m.to_dict()

returned_dict = s.to_dict()
for derived_property in s.get_global_properties().keys():
returned_dict.pop(derived_property, None)

assert returned_dict == m.to_dict()

# check append_atom works properly
m.add_atom(
Expand Down
Loading