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

export trajectory #29

Merged
merged 1 commit into from
Feb 26, 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: 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
Loading