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]? - Animate does not appear to work #793

Closed
coltonbh opened this issue Jul 11, 2024 · 5 comments
Closed

[BUG]? - Animate does not appear to work #793

coltonbh opened this issue Jul 11, 2024 · 5 comments
Labels

Comments

@coltonbh
Copy link

coltonbh commented Jul 11, 2024

Describe the bug
Running viewer.animate does not appear to work. Am I doing something wrong?

To Reproduce

import py3Dmol as p3d

# Convert all structures to XYZ strings
xyz_strings = [structure.to_xyz() for structure in xtb_opt.results.structures]

# Create the viewer
viewer = p3d.view(width=800, height=600)

# Add all models to the viewer and set the frames for animation
for xyz in xyz_strings:
    viewer.addModel(xyz, "xyz")

viewer.setStyle({"stick": {}, "sphere": {"scale": 0.25}})
viewer.zoomTo()

# Set animation parameters
viewer.animate({'interval': 100, 'loop': 'forward', 'reps': 0})

# Display the viewer
viewer.show()

Expected behavior
I would expect the image to be animated. Instead all the images are superimposed without any animation.

Screenshots
image
Desktop (please complete the following information):

  • OS: Linux
  • Browser Same result in VSCode, Chrome, Firefox, etc.
  • Version 2.2.0

Additional context

Thanks so much!

@coltonbh coltonbh added the bug label Jul 11, 2024
@dkoes
Copy link
Contributor

dkoes commented Jul 11, 2024

You are adding each structure as an individual model. You need to add them as frames. Concat all the xyz files together and pass the string to addModelsAsFrames.
https://3dmol.csb.pitt.edu/doc/GLViewer.html#addModelsAsFrames

@coltonbh
Copy link
Author

Lemme give this a try!

@coltonbh
Copy link
Author

coltonbh commented Jul 11, 2024

Amazing! This works like a charm:

import py3Dmol as p3d

# Convert all structures to XYZ strings
xyz_strings = [structure.to_xyz() for structure in xtb_opt.results.structures]
xyz_total = "".join(xyz_strings)

# Create the viewer
viewer = p3d.view(width=800, height=600)

# Add all models to the viewer and set the frames for animation
viewer.addModelsAsFrames(xyz_total, "xyz")
viewer.setStyle({"stick": {}, "sphere": {"scale": 0.25}})
viewer.zoomTo()

# Set animation parameters
viewer.animate({'interval': 100, 'loop': 'forward', 'reps': 0})

# Display the viewer
viewer.show()

Thanks for the quick help. Love py3Dmol and having good support makes it so much more usable :)

A final question--is there a way to add a slider for the animation so I can investigate a trajectory one frame at a time instead of an automatic loop animation?

Thanks!

@dkoes
Copy link
Contributor

dkoes commented Jul 12, 2024

That's issue #790. It isn't something that belongs in the main library, but in the UI wrapper, and it hasn't been implemented yet.

@coltonbh
Copy link
Author

Excellent. Thanks so much for the guidance and feedback. I've build a few cool things on top of py3Dmol and will ping you when they're ready. Thanks for such a great library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants