cosmol-viewer 0.1.6__pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ from .cosmol_viewer import *
2
+
3
+ __doc__ = cosmol_viewer.__doc__
4
+ if hasattr(cosmol_viewer, "__all__"):
5
+ __all__ = cosmol_viewer.__all__
@@ -0,0 +1,389 @@
1
+ from typing import Optional, Union, List
2
+
3
+ def parse_sdf(
4
+ sdf: str,
5
+ keep_h: bool = True,
6
+ multimodel: bool = True,
7
+ onemol: bool = False
8
+ ) -> "MoleculeData":
9
+ """
10
+ Parse an SDF string into molecule data.
11
+
12
+ # Args
13
+ - sdf: Path to an SD string containing SDF content.
14
+ - keep_h: Whether to keep explicit hydrogen atoms (default: True).
15
+ - multimodel: Whether to allow multiple models in one file (default: True).
16
+ - onemol: Whether to merge multiple models into one molecule (default: False).
17
+
18
+ # Returns
19
+ - MoleculeData: Parsed molecule data object.
20
+
21
+ # Example
22
+ ```python
23
+ from cosmol_viewer import parse_sdf
24
+ mol = parse_sdf(open("./molecule.sdf", "r", encoding="utf-8").read())
25
+ ```
26
+ """
27
+ ...
28
+
29
+ def parse_mmcif(
30
+ mmcif: str
31
+ ) -> "ProteinData":
32
+ """
33
+ Parse an MMCIF string into protein data.
34
+
35
+ # Args
36
+ - mmcif: Path to an MMCIF string containing MMCIF content.
37
+
38
+ # Returns
39
+ - ProteinData: Parsed protein data object.
40
+
41
+ # Example
42
+ ```python
43
+ from cosmol_viewer import parse_mmcif
44
+ prot = parse_mmcif(open("./protein.cif", "r", encoding="utf-8").read())
45
+ ```
46
+ """
47
+ ...
48
+
49
+ class Scene:
50
+ """
51
+ A 3D scene container for visualizing molecular or geometric shapes.
52
+
53
+ This class allows adding, updating, and removing shapes in a 3D scene,
54
+ as well as modifying scene-level properties like scale and background color.
55
+
56
+ Supported shape types:
57
+ - PySphere
58
+ - PyStick
59
+ - PyMolecules
60
+
61
+ Shapes can be optionally identified with a string `id`,
62
+ which allows updates and deletion.
63
+ """
64
+
65
+ def __init__(self) -> None:
66
+ """
67
+ Creates a new empty scene.
68
+
69
+ # Example
70
+ ```python
71
+ scene = Scene()
72
+ ```
73
+ """
74
+ ...
75
+
76
+ def add_shape(self, shape: Union["Sphere", "Stick", "Molecules", "Protein"], id: Optional[str] = None) -> None:
77
+ """
78
+ Add a shape to the scene.
79
+
80
+ # Args
81
+ - shape: A shape instance (Sphere, Stick, Molecules, or Protein).
82
+ - id: Optional string ID to associate with the shape.
83
+
84
+ If the `id` is provided and a shape with the same ID exists,
85
+ the new shape will replace it.
86
+
87
+ # Example
88
+ ```python
89
+ scene.add_shape(sphere)
90
+ scene.add_shape(stick, id="bond1")
91
+ ```
92
+ """
93
+ ...
94
+
95
+ def update_shape(self, id: str, shape: Union["Sphere", "Stick", "Molecules", "Protein"]) -> None:
96
+ """
97
+ Update an existing shape in the scene by its ID.
98
+
99
+ # Args
100
+ - id: ID of the shape to update.
101
+ - shape: New shape object to replace the existing one.
102
+
103
+ # Example
104
+ ```python
105
+ scene.update_shape("atom1", updated_sphere)
106
+ ```
107
+ """
108
+ ...
109
+
110
+ def delete_shape(self, id: str) -> None:
111
+ """
112
+ Remove a shape from the scene by its ID.
113
+
114
+ # Args
115
+ - id: ID of the shape to remove.
116
+
117
+ # Example
118
+ ```python
119
+ scene.delete_shape("bond1")
120
+ ```
121
+ """
122
+ ...
123
+
124
+ def recenter(self, center: List[float]) -> None:
125
+ """
126
+ Recenter the scene at a given point.
127
+
128
+ # Args
129
+ - center: An XYZ array of 3 float values representing the new center.
130
+
131
+ # Example
132
+ ```python
133
+ scene.recenter([0.0, 0.0, 0.0])
134
+ ```
135
+ """
136
+ ...
137
+
138
+ def scale(self, scale: float) -> None:
139
+ """
140
+ Set the global scale factor of the scene.
141
+
142
+ This affects the visual size of all shapes uniformly.
143
+
144
+ # Args
145
+ - scale: A positive float scaling factor.
146
+
147
+ # Example
148
+ ```python
149
+ scene.scale(1.5)
150
+ ```
151
+ """
152
+ ...
153
+
154
+ def set_background_color(self, background_color: List[float]) -> None:
155
+ """
156
+ Set the background color of the scene.
157
+
158
+ # Args
159
+ - background_color: An RGB array of 3 float values between 0.0 and 1.0.
160
+
161
+ # Example
162
+ ```python
163
+ scene.set_background_color([1.0, 1.0, 1.0]) # white background
164
+ ```
165
+ """
166
+ ...
167
+
168
+ def use_black_background(self) -> None:
169
+ """
170
+ Set the background color of the scene to black.
171
+
172
+ # Example
173
+ ```python
174
+ scene.use_black_background()
175
+ ```
176
+ """
177
+ ...
178
+
179
+ class Viewer:
180
+ """
181
+ A viewer that renders 3D scenes in different runtime environments
182
+ (e.g., Jupyter, Colab, or native GUI).
183
+
184
+ The `Viewer` automatically selects a backend:
185
+ - Jupyter/Colab → WebAssembly canvas (inline display)
186
+ - Python script/terminal → native GUI window (if supported)
187
+
188
+ Use `Viewer.render(scene)` to create and display a viewer instance.
189
+ """
190
+
191
+ @staticmethod
192
+ def get_environment() -> str:
193
+ """
194
+ Get the current runtime environment.
195
+
196
+ # Returns
197
+ - str: One of "Jupyter", "Colab", "PlainScript", or "IPythonTerminal".
198
+
199
+ # Example
200
+ ```python
201
+ env = Viewer.get_environment()
202
+ print(env) # e.g., "Jupyter"
203
+ ```
204
+ """
205
+ ...
206
+
207
+ @staticmethod
208
+ def render(scene: "Scene", width: float = 800.0, height: float = 600.0) -> "Viewer":
209
+ """
210
+ Render a 3D scene.
211
+
212
+ # Args
213
+ - scene: The scene to render.
214
+ - width: The viewport width in pixels (default: 800).
215
+ - height: The viewport height in pixels (default: 600).
216
+
217
+ # Returns
218
+ - Viewer: The created viewer instance.
219
+
220
+ # Example
221
+ ```python
222
+ from cosmol_viewer import Viewer, Scene, Sphere
223
+ scene = Scene()
224
+ scene.add_shape(Sphere([0, 0, 0], 1.0))
225
+ viewer = Viewer.render(scene)
226
+ ```
227
+ """
228
+ ...
229
+
230
+ @staticmethod
231
+ def play(
232
+ frames: List["Scene"],
233
+ interval: float,
234
+ loops: int,
235
+ width: float = 800.0,
236
+ height: float = 600.0,
237
+ smooth: bool = False
238
+ ) -> "Viewer":
239
+ """
240
+ Play an animation of multiple frames.
241
+
242
+ # Args
243
+ - frames: List of Scene objects as animation frames.
244
+ - interval: Frame interval in seconds.
245
+ - loops: Number of loops to repeat (-1 for infinite).
246
+ - width: The viewport width in pixels.
247
+ - height: The viewport height in pixels.
248
+ - smooth: Whether to smooth the animation by
249
+ interpolating between frames.
250
+
251
+ # Returns
252
+ - Viewer: The created viewer instance.
253
+
254
+ # Example
255
+ ```python
256
+ viewer = Viewer.play([scene1, scene2], interval=0.5, loops=3)
257
+ ```
258
+ """
259
+ ...
260
+
261
+ def update(self, scene: "Scene") -> None:
262
+ """
263
+ Update the viewer with a new scene.
264
+
265
+ Works for both Web-based rendering (Jupyter/Colab) and native GUI windows.
266
+
267
+ ⚠️ Note (Jupyter/Colab): Animation updates may be limited by
268
+ notebook rendering capacity.
269
+
270
+ # Args
271
+ - scene: The updated scene.
272
+
273
+ # Example
274
+ ```python
275
+ scene.add_shape(Sphere([1, 1, 1], 0.5))
276
+ viewer.update(scene)
277
+ ```
278
+ """
279
+ ...
280
+
281
+ def save_image(self, path: str) -> None:
282
+ """
283
+ Save the current image to a file.
284
+
285
+ # Args
286
+ - path: File path for the saved image.
287
+
288
+ # Example
289
+ ```python
290
+ viewer.save_image("output.png")
291
+ ```
292
+ """
293
+ ...
294
+
295
+ class Sphere:
296
+ """
297
+ A sphere shape in the scene.
298
+
299
+ # Args
300
+ - center: [x, y, z] coordinates of the sphere center.
301
+ - radius: Radius of the sphere.
302
+
303
+ # Example
304
+ ```python
305
+ sphere = Sphere([0, 0, 0], 1.0).color([1, 0, 0])
306
+ ```
307
+ """
308
+
309
+ def __init__(self, center: List[float], radius: float) -> None: ...
310
+ def set_center(self, center: List[float]) -> "Sphere": ...
311
+ def set_radius(self, radius: float) -> "Sphere": ...
312
+ def color(self, color: List[float]) -> "Sphere": ...
313
+ def color_rgba(self, color: List[float]) -> "Sphere": ...
314
+ def opacity(self, opacity: float) -> "Sphere": ...
315
+
316
+
317
+ class Stick:
318
+ """
319
+ A cylindrical stick (or capsule) connecting two points.
320
+
321
+ # Args
322
+ - start: Starting point [x, y, z].
323
+ - end: Ending point [x, y, z].
324
+ - thickness: Stick radius.
325
+
326
+ # Example
327
+ ```python
328
+ stick = Stick([0,0,0], [1,1,1], 0.1).opacity(0.5)
329
+ ```
330
+ """
331
+
332
+ def __init__(self, start: List[float], end: List[float], thickness: float) -> None: ...
333
+ def color(self, color: List[float]) -> "Stick": ...
334
+ def color_rgba(self, color: List[float]) -> "Stick": ...
335
+ def opacity(self, opacity: float) -> "Stick": ...
336
+ def set_thickness(self, thickness: float) -> "Stick": ...
337
+ def set_start(self, start: List[float]) -> "Stick": ...
338
+ def set_end(self, end: List[float]) -> "Stick": ...
339
+
340
+
341
+ class Molecules:
342
+ """
343
+ A molecular shape object.
344
+
345
+ # Example
346
+ ```python
347
+ mol = parse_sdf(open("molecule.sdf", "r", encoding="utf-8").read())
348
+ molecules = Molecules(mol).centered().color([0,1,0])
349
+ ```
350
+ """
351
+
352
+ def __init__(self, molecule_data: "MoleculeData") -> None: ...
353
+ def get_center(self) -> List[float]: ...
354
+ def centered(self) -> "Molecules": ...
355
+ def color(self, color: List[float]) -> "Molecules": ...
356
+ def color_rgba(self, color: List[float]) -> "Molecules": ...
357
+ def opacity(self, opacity: float) -> "Molecules": ...
358
+ def reset_color(self) -> "Molecules": ...
359
+
360
+ class MoleculeData:
361
+ """
362
+ Internal representation of molecule data returned by `parse_sdf`.
363
+ """
364
+ ...
365
+
366
+ class Protein:
367
+ """
368
+ A protein shape object.
369
+
370
+ # Example
371
+ ```python
372
+ mmcif_data = parse_mmcif(open("2AMD.cif", "r", encoding="utf-8").read())
373
+ prot = Protein(mmcif_data).centered().color([0,1,0])
374
+ ```
375
+ """
376
+
377
+ def __init__(self, mmcif_data: "ProteinData") -> None: ...
378
+ def get_center(self) -> List[float]: ...
379
+ def centered(self) -> "Protein": ...
380
+ def color(self, color: List[float]) -> "Protein": ...
381
+ def color_rgba(self, color: List[float]) -> "Protein": ...
382
+ def opacity(self, opacity: float) -> "Protein": ...
383
+ def reset_color(self) -> "Protein": ...
384
+
385
+ class ProteinData:
386
+ """
387
+ Internal representation of protein data returned by `parse_mmcif`.
388
+ """
389
+ ...
cosmol_viewer/py.typed ADDED
File without changes
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.4
2
+ Name: cosmol-viewer
3
+ Version: 0.1.6
4
+ Summary: Molecular visualization tools
5
+ Author-email: 95028 <wjt@cosmol.org>
6
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
7
+ Project-URL: Repository, https://github.com/COSMol-repl/COSMol-viewer
8
+
9
+ # COSMol-viewer
10
+ A high-performance molecular viewer for Python and Rust, powered by a unified Rust core.
11
+ It supports both in-notebook visualization and native desktop rendering, with smooth playback for scientific animations.
12
+
13
+ <div align="center">
14
+ <a href="https://crates.io/crates/cosmol_viewer">
15
+ <img src="https://img.shields.io/crates/v/cosmol_viewer.svg" alt="crates.io Latest Release" />
16
+ </a>
17
+ <a href="https://pypi.org/project/cosmol_viewer/">
18
+ <img src="https://img.shields.io/pypi/v/cosmol_viewer.svg" alt="PyPi Latest Release" />
19
+ </a>
20
+ <a href="https://cosmol-repl.github.io/COSMol-viewer">
21
+ <img src="https://img.shields.io/badge/docs-latest-blue.svg" alt="Documentation Status" />
22
+ </a>
23
+ </div>
24
+
25
+ COSMol-viewer is a compact, cross-platform renderer for molecular and geometric scenes.
26
+ Unlike purely notebook-bound solutions such as py3Dmol, COSMol-viewer runs everywhere:
27
+
28
+ - Native desktop window (Python or Rust) via `egui`
29
+ - Jupyter / IPython notebook via WASM backend
30
+ - Rust applications
31
+
32
+ All implementations share the same Rust rendering engine, ensuring consistent performance and visual output.
33
+
34
+ ---
35
+
36
+ ## Quick concepts
37
+
38
+ - **Scene**: container for shapes (molecules, proteins, spheres, etc.).
39
+ - **Viewer.render(scene, ...)**: create a static viewer bound to a canvas (native or notebook). Good for static visualization.
40
+ - **viewer.update(scene)**: push incremental changes after `Viewer.render()` (real-time / streaming use-cases).
41
+ - **Viewer.play(frames, interval, loops, width, height, smooth)**: *recommended* for precomputed animations and demonstrations. The viewer takes care of playback timing and looping.
42
+
43
+ **Why prefer `play` for demos?**
44
+ - Single call API (hand off responsibility to the viewer).
45
+ - Built-in timing & loop control.
46
+ - Optional `smooth` interpolation between frames for visually pleasing playback even when input frame rate is low.
47
+
48
+ **Why keep `update`?**
49
+ - `update` is ideal for real-time simulations, MD runs, or streaming data where frames are not precomputed. It provides strict fidelity (no interpolation) and minimal latency.
50
+
51
+ ---
52
+
53
+ # Usage
54
+
55
+ ## python
56
+ See examples in [Google Colab](https://colab.research.google.com/drive/1Sw72QWjQh_sbbY43jGyBOfF1AQCycmIx?usp=sharing).
57
+
58
+ Install with `pip install cosmol-viewer`
59
+
60
+ ### 1. Static molecular rendering
61
+
62
+ ```python
63
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
64
+
65
+ mol_data = parse_sdf(open("molecule.sdf", "r", encoding="utf-8").read())
66
+
67
+ mol = Molecules(mol_data).centered()
68
+
69
+ scene = Scene()
70
+ scene.add_shape(mol, "mol")
71
+
72
+ viewer = Viewer.render(scene, width=600, height=400)
73
+
74
+ print("Press Any Key to exit...", end='', flush=True)
75
+ _ = input() # Keep the viewer open until you decide to close
76
+ ```
77
+
78
+ ### 2. Animation playback with `Viewer.play`
79
+
80
+ ```python
81
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
82
+
83
+ frames = []
84
+
85
+ for i in range(1, 10):
86
+ with open(f"frames/frame_{i}.sdf", "r") as f:
87
+ sdf = f.read()
88
+ mol = Molecules(parse_sdf(sdf)).centered()
89
+
90
+ scene = Scene()
91
+ scene.add_shape(mol, "mol")
92
+ frames.append(scene)
93
+
94
+ Viewer.play(frames, interval=0.033, loops=-1, width=800, height=500, smooth=True) # loops=-1 for infinite repeat
95
+ ```
96
+
97
+ more examples can be found in the [examples](https://github.com/COSMol-repl/COSMol-viewer/tree/main/cosmol_viewer/examples) folder:
98
+ ```bash
99
+ cd cosmol_viewer
100
+ python .\examples\render_protein.py
101
+ ```
102
+
103
+ # Documentation
104
+
105
+ Please check out our documentation at [here](https://cosmol-repl.github.io/COSMol-viewer/).
106
+
107
+ ---
108
+
109
+ # Contact
110
+
111
+ For any questions, issues, or suggestions, please contact [wjt@cosmol.org](mailto:wjt@cosmol.org) or open an issue in the repository. We will review and address them as promptly as possible.
@@ -0,0 +1,7 @@
1
+ cosmol_viewer-0.1.6.dist-info/METADATA,sha256=Lu1Xtd1o0zIwcHgqIehpVQeL-A_jyr_aTkK7FdTUtJc,3984
2
+ cosmol_viewer-0.1.6.dist-info/WHEEL,sha256=km1pez3RCwUFhbaYJ6rBbOfnQwuFYY-aODKgU5VkVEE,157
3
+ cosmol_viewer/__init__.py,sha256=K33zoYpHqUVvpFdMVxmCtw4uKj9ZXrGuQD4D4DuUmjk,135
4
+ cosmol_viewer/__init__.pyi,sha256=dHeDzQd2wiBI2j6byAn6bxnVRxXNGVRBDYLaHPYVr4c,10210
5
+ cosmol_viewer/cosmol_viewer.pypy311-pp73-x86-linux-gnu.so,sha256=ER7kK_oIu6hbNZpZwhcuELoNB4Ndfe3gTVY5d7nzpqg,14092772
6
+ cosmol_viewer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ cosmol_viewer-0.1.6.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: pp311-pypy311_pp73-manylinux_2_17_i686
5
+ Tag: pp311-pypy311_pp73-manylinux2014_i686