-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Hi, I would like to create a trajectory in molviewspec. I know its possible to load trajectories in .pdf/cif files but I would like to build a trajectory from primitives. Currently I'm using the snapshot functionality but this doesnt fully meet my requirements since the camera resets on on each frame.
Example code:
(reduced so it fits as uri)
from molviewspec import create_builder, States, GlobalMetadata
import urllib.parse
import numpy as np
def axis_arrows(builder, opacity=1.0):
return (
builder.primitives(opacity=opacity)
.arrow(
start=(0, 0, 0),
end=(1, 0, 0),
color="red",
tooltip="X",
show_end_cap=True,
)
.arrow(
start=(0, 0, 0),
end=(0, 1, 0),
color="green",
tooltip="Y",
show_end_cap=True,
)
.arrow(
start=(0, 0, 0),
end=(0, 0, 1),
color="blue",
tooltip="Z",
show_end_cap=True,
)
)
# %%
r = 2
# N = 12
N = 6
phi = np.linspace(0, 2 * np.pi, N, endpoint=False)
phi += np.pi / 2
phi %= 2 * np.pi
phi = phi[::-1]
x, y = r * np.cos(phi), r * np.sin(phi)
metadata = GlobalMetadata(title="clock", description="one-handed")
snapshots = []
for i, (xi, yi) in enumerate(zip(x, y)):
builder = create_builder()
# axis_arrows(builder)
builder.primitives().arrow(
start=(0, 0, 0), end=(xi, yi, 0), color="black", show_end_cap=True
)
# builder.primitives().sphere(center=(0, 0, 0), radius=0.1, color="black")
# builder.camera(target=(0, 0, 0), position=(0, 0, 10), up=(0, 1, 0))
snapshot = builder.get_snapshot(title=str(i))
snapshots.append(snapshot)
states = States(
snapshots=snapshots,
metadata=metadata,
).model_dump_json(indent=None, exclude_none=True)
encoded_states = urllib.parse.quote(states)
url = f"https://molstar.org/viewer/?mvs-data={encoded_states}"
print(url)
Which yields the following: link
Which shows the camera resetting after the users drags to move.
Possibly related to #21
Metadata
Metadata
Assignees
Labels
No labels