Skip to content

Commit

Permalink
export trajectory
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Feb 26, 2024
1 parent d3846a3 commit 56c248e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions weas_widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ function render({ model, el }) {
});
// Listen for the custom 'atomsUpdated' event
viewerElement.addEventListener('atomsUpdated', (event) => {
const updatedAtoms = event.detail.to_dict(); // event.detail contains the updated atoms
updatedAtoms.uuid = avr.atoms.uuid;
model.set("atoms", updatedAtoms);
// event detail is a trajectory: a array of atoms data
// loop all the atoms and export to a dict
const trajectory = [];
event.detail.forEach((atomsData) => {
trajectory.push(atomsData.to_dict());
});
trajectory.uuid = avr.uuid;
model.set("atoms", trajectory);
model.save_changes();
// console.log("updatedAtoms: ", trajectory);
console.log("Updated atoms from event.")
});
// Listen for the custom 'viewerUpdated' event
Expand Down
3 changes: 2 additions & 1 deletion weas_widget/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def to_ase(cls, weas_atoms):

# if atoms is a list of atoms, convert all atoms to a list of ase atoms
if isinstance(weas_atoms, list):
return [cls.to_ase(atom) for atom in weas_atoms]
trajectory = [cls.to_ase(atom) for atom in weas_atoms]
return trajectory[0] if len(trajectory) == 1 else trajectory
symbols = [weas_atoms["species"][s][0] for s in weas_atoms["speciesArray"]]
positions = weas_atoms["positions"]
cell = np.array(weas_atoms["cell"]).reshape(3, 3)
Expand Down

0 comments on commit 56c248e

Please sign in to comment.