Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.
Closed
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
9 changes: 6 additions & 3 deletions src/equisolve/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ def ase_to_tensormap(
positions_gradients = None

if stress is not None:
cell_gradients = [-f.arrays[stress] for f in frames]
cell_gradients = [-f.info[stress] for f in frames]
else:
cell_gradients = None

return properties_to_tensormap(values, positions_gradients, cell_gradients)
return properties_to_tensormap(
values, positions_gradients, cell_gradients, property_name=energy
)


def properties_to_tensormap(
values: List[float],
positions_gradients: List[np.ndarray] = None,
cell_gradients: List[np.ndarray] = None,
is_structure_property: bool = True,
property_name: str = "property",
) -> TensorMap:
"""Create a :class:`equistore.TensorMap` from array like properties.

Expand Down Expand Up @@ -94,7 +97,7 @@ def properties_to_tensormap(
values=np.asarray(values).reshape(-1, 1),
samples=Labels(["structure"], np.arange(n_structures).reshape(-1, 1)),
components=[],
properties=Labels(["property"], np.array([(0,)])),
properties=Labels([property_name], np.array([(0,)])),
)

if positions_gradients is not None:
Expand Down
2 changes: 1 addition & 1 deletion tests/equisolve_tests/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_ase_to_tensormap(self, energies, forces, stress):
frame = ase.Atoms(self.n_atoms * "H")
frame.info["energy"] = energies[i]
frame.arrays["forces"] = forces[i]
frame.arrays["stress"] = stress[i]
frame.info["stress"] = stress[i]
frames.append(frame)

property_tm = ase_to_tensormap(frames, "energy", "forces", "stress")
Expand Down