py3Dmol 2.5.4__tar.gz → 3.0.0__tar.gz
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.
- py3dmol-3.0.0/PKG-INFO +234 -0
- py3dmol-3.0.0/README.md +201 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/py3Dmol/__init__.py +129 -34
- py3dmol-3.0.0/py3Dmol.egg-info/PKG-INFO +234 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/setup.cfg +0 -1
- {py3dmol-2.5.4 → py3dmol-3.0.0}/setup.py +2 -3
- py3dmol-2.5.4/PKG-INFO +0 -84
- py3dmol-2.5.4/README.md +0 -52
- py3dmol-2.5.4/py3Dmol.egg-info/PKG-INFO +0 -84
- {py3dmol-2.5.4 → py3dmol-3.0.0}/LICENSE.txt +0 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/MANIFEST.in +0 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/py3Dmol.egg-info/SOURCES.txt +0 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/py3Dmol.egg-info/dependency_links.txt +0 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/py3Dmol.egg-info/requires.txt +0 -0
- {py3dmol-2.5.4 → py3dmol-3.0.0}/py3Dmol.egg-info/top_level.txt +0 -0
py3dmol-3.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py3Dmol
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: An IPython interface for embedding 3Dmol.js views in Jupyter notebooks
|
|
5
|
+
Home-page: https://3dmol.org
|
|
6
|
+
Author: David Koes
|
|
7
|
+
Author-email: dkoes@pitt.edu
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: molecule protein visualization
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
Provides-Extra: ipython
|
|
21
|
+
Requires-Dist: IPython; extra == "ipython"
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description
|
|
26
|
+
Dynamic: description-content-type
|
|
27
|
+
Dynamic: home-page
|
|
28
|
+
Dynamic: keywords
|
|
29
|
+
Dynamic: license
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
Dynamic: provides-extra
|
|
32
|
+
Dynamic: summary
|
|
33
|
+
|
|
34
|
+
py3Dmol
|
|
35
|
+
=======
|
|
36
|
+
|
|
37
|
+
A simple [IPython/Jupyter](http://jupyter.org/) widget to
|
|
38
|
+
embed an interactive [3Dmol.js](http://3dmol.org) viewer in a notebook.
|
|
39
|
+
|
|
40
|
+
The widget emits HTML and JavaScript. Once displayed, it remains interactive
|
|
41
|
+
without a running IPython kernel, but communication is one-way: Python queues
|
|
42
|
+
commands for the browser and cannot read JavaScript return values or receive
|
|
43
|
+
viewer events. Exported pages still need JavaScript and WebGL enabled, plus access
|
|
44
|
+
to the configured library URL and any remotely loaded molecular data.
|
|
45
|
+
|
|
46
|
+
If you experience problems, please file
|
|
47
|
+
an [issue](https://github.com/3dmol/3Dmol.js/issues).
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
[An example notebook](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/master/py3Dmol/examples.ipynb)
|
|
51
|
+
|
|
52
|
+
Installation
|
|
53
|
+
------------
|
|
54
|
+
|
|
55
|
+
From PyPI:
|
|
56
|
+
|
|
57
|
+
pip install py3Dmol
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Usage
|
|
61
|
+
-----
|
|
62
|
+
|
|
63
|
+
Open a notebook
|
|
64
|
+
|
|
65
|
+
jupyter notebook
|
|
66
|
+
|
|
67
|
+
and issue
|
|
68
|
+
|
|
69
|
+
```Python
|
|
70
|
+
import py3Dmol
|
|
71
|
+
view = py3Dmol.view(query='pdb:1ubq')
|
|
72
|
+
view.setStyle({'cartoon':{'color':'spectrum'}})
|
|
73
|
+
view
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
API
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
Use the [$3Dmol.GLViewer reference](https://3dmol.org/doc/GLViewer.html) for
|
|
80
|
+
method names and argument objects. The wrapper translates positional arguments
|
|
81
|
+
into JavaScript using JSON serialization; use Python dictionaries for selections
|
|
82
|
+
and styles, and Python `True`, `False`, and `None` for their JSON equivalents.
|
|
83
|
+
Python functions cannot be passed as JavaScript callbacks.
|
|
84
|
+
|
|
85
|
+
Most forwarded methods queue a command and return the Python `view` for chaining,
|
|
86
|
+
not the JavaScript result. For example, a forwarded `addModel` call does not return
|
|
87
|
+
a model object, and a forwarded `selectedAtoms` call does not return atoms to
|
|
88
|
+
Python. `getModel()` is a wrapper-specific exception: it returns a model proxy
|
|
89
|
+
whose methods queue calls to the JavaScript [GLModel](https://3dmol.org/doc/GLModel.html).
|
|
90
|
+
Promises and browser-side values do not cross back into Python.
|
|
91
|
+
|
|
92
|
+
Display and export helpers
|
|
93
|
+
--------------------------
|
|
94
|
+
|
|
95
|
+
| Operation | Python helper |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| Display a new viewer | Evaluate the view as the last notebook expression, or call `show()` |
|
|
98
|
+
| Apply queued commands to the displayed viewer | `update()` |
|
|
99
|
+
| Return embeddable HTML as a Python string | `write_html()` |
|
|
100
|
+
| Write an HTML page to a path or writable file object | `write_html(f)`; `fullpage=True` fills the page when writing a file |
|
|
101
|
+
| Display a still or animated image in notebook output | `png()` or `apng(nframes)` after the viewer has been displayed |
|
|
102
|
+
|
|
103
|
+
Repeated `show()` calls create new displays; subsequent `update()` calls target the
|
|
104
|
+
most recently displayed instance. Image helpers publish browser output rather
|
|
105
|
+
than returning image bytes to Python. Notebook output must allow the embedded
|
|
106
|
+
JavaScript to run; if the viewer fails to load, inspect the browser console.
|
|
107
|
+
|
|
108
|
+
Use `viewergrid=(rows, columns)` to create a grid. Forwarded commands apply to
|
|
109
|
+
every cell unless `viewer=(row, column)` selects one, with zero-based indices.
|
|
110
|
+
`getModel` requires an explicit `viewer` when a grid is enabled. Constructor
|
|
111
|
+
option `linked=True` links mouse controls across the grid.
|
|
112
|
+
|
|
113
|
+
The `js` constructor argument selects the 3Dmol.js bundle URL. Match that bundle
|
|
114
|
+
to the API documentation you use. The library is loaded once per page, so changing
|
|
115
|
+
`js` on a later view does not replace an already loaded library.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
Editing, trajectory, and classroom controls
|
|
119
|
+
-------------------------------------------
|
|
120
|
+
|
|
121
|
+
These optional constructor arguments enable browser controls in notebooks and
|
|
122
|
+
exported HTML. All three features are disabled by default.
|
|
123
|
+
|
|
124
|
+
| Argument | Behavior |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `edit=True` | Show the edit button for models, styles, surfaces, volumes, and measurements |
|
|
127
|
+
| `trajectory=True` | Enable trajectory controls for models loaded with frames, such as through `addModelsAsFrames` |
|
|
128
|
+
| `learning=True` | Show the classroom button and session-name dialog |
|
|
129
|
+
| `learning={...}` | Configure the classroom with the options below |
|
|
130
|
+
| `ui_js="..."` | Override the optional UI bundle URL |
|
|
131
|
+
|
|
132
|
+
All views default to the same pinned 3Dmol.js release on jsDelivr, with or without
|
|
133
|
+
controls. The UI bundle loads automatically when any controls are requested;
|
|
134
|
+
its URL is the sibling `3Dmol.ui.js` or `3Dmol.ui-min.js` of the core `js` URL.
|
|
135
|
+
To use another release or a hosted build, set `js` explicitly and use matching
|
|
136
|
+
core and UI builds. For a custom core filename, supply `ui_js` explicitly.
|
|
137
|
+
Use the same bundle URLs for every view on a page: the first core and UI bundles
|
|
138
|
+
loaded are reused by later views. Restart the notebook output page to switch
|
|
139
|
+
bundles. The examples below use the default released bundles.
|
|
140
|
+
|
|
141
|
+
Controls apply to one viewer. Grids with more than one cell share a container and
|
|
142
|
+
canvas, so they cannot use these options; create separate `view` objects for
|
|
143
|
+
independent controls or classrooms. A `viewergrid=(1, 1)` is supported.
|
|
144
|
+
|
|
145
|
+
<!-- example: viewer-controls -->
|
|
146
|
+
```python
|
|
147
|
+
import py3Dmol
|
|
148
|
+
|
|
149
|
+
frames = ("2\nFrame 0\nC 0 0 0\nO 1.2 0 0\n"
|
|
150
|
+
"2\nFrame 1\nC 0 0 0\nO 1.5 0 0\n")
|
|
151
|
+
view = py3Dmol.view(width=640, height=400, edit=True, trajectory=True,
|
|
152
|
+
learning=True)
|
|
153
|
+
view.addModelsAsFrames(frames, "xyz")
|
|
154
|
+
view.setStyle({}, {"stick": {}, "sphere": {"scale": 0.3}})
|
|
155
|
+
view.zoomTo()
|
|
156
|
+
html = view.write_html()
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Display `view` in a notebook, or save `html` to embed the same controls in a page.
|
|
160
|
+
Use the classroom button to create a session or join an existing one. Pass a
|
|
161
|
+
dictionary such as `learning={"mode": "button", "session": "my-class"}` to
|
|
162
|
+
prefill the session name. Browser edits and classroom events are not returned to
|
|
163
|
+
Python; `write_html()` exports the commands queued in Python, not subsequent
|
|
164
|
+
browser edits.
|
|
165
|
+
|
|
166
|
+
For hidden activation, set `mode` to `"hidden"` and provide a nonempty, unique
|
|
167
|
+
`session` identifier. Give every participant the same identifier and server.
|
|
168
|
+
The classroom button stays hidden while waiting. Focus the instructor's viewer
|
|
169
|
+
and press **Ctrl+Alt+I** to start; other active viewers with that configuration
|
|
170
|
+
automatically join as students, including viewers opened later.
|
|
171
|
+
|
|
172
|
+
<!-- example: hidden-classroom -->
|
|
173
|
+
```python
|
|
174
|
+
import py3Dmol
|
|
175
|
+
|
|
176
|
+
xyz = "2\nCarbon monoxide\nC 0 0 0\nO 1.2 0 0\n"
|
|
177
|
+
view = py3Dmol.view(width=640, height=400, data=xyz, format="xyz",
|
|
178
|
+
style={"sphere": {"scale": 0.3}, "stick": {}},
|
|
179
|
+
learning={"mode": "hidden", "session": "py3dmol-bonding-class-a"})
|
|
180
|
+
html = view.write_html()
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Replace the example session identifier with one unique to your class and viewer.
|
|
184
|
+
The instructor gets the usual editing, trajectory, and classroom controls.
|
|
185
|
+
Student editing and trajectory controls are disabled while following; students
|
|
186
|
+
can still rotate, zoom, and answer atom queries. A session ends when the
|
|
187
|
+
instructor leaves or closes their viewer.
|
|
188
|
+
|
|
189
|
+
The `learning` dictionary accepts the JSON options from
|
|
190
|
+
[`LearningConfig`](https://3dmol.org/doc/LearningConfig.html): `mode`, `session`,
|
|
191
|
+
`server`, `hotkey`, and `clientURL`. `server` defaults to `"https://3dmol.csb.pitt.edu"`;
|
|
192
|
+
set it to your session server's origin, including protocol and port when needed,
|
|
193
|
+
for example `"http://127.0.0.1:5072"`. `hotkey` changes the hidden activation
|
|
194
|
+
shortcut, and `clientURL` overrides the Socket.IO browser-client script. Python
|
|
195
|
+
callbacks, including `socketFactory` and adapter hooks, are not supported.
|
|
196
|
+
|
|
197
|
+
See the [learning-environment guide](https://github.com/3dmol/3Dmol.js/blob/master/tutorials/learning_environment.md)
|
|
198
|
+
for shared scene behavior, classroom controls, and server setup. Hidden mode
|
|
199
|
+
changes how controls appear; it does not authenticate instructors.
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
Export a grid with independent styles
|
|
203
|
+
------------------------------------
|
|
204
|
+
|
|
205
|
+
This example puts the same inline molecule in two cells, then styles each cell's
|
|
206
|
+
model separately. `addModel` and `zoomTo` target both cells; `getModel` selects one
|
|
207
|
+
cell. `write_html()` returns an HTML fragment that can be saved or embedded in a
|
|
208
|
+
page without an active notebook kernel. The fragment still loads the JavaScript
|
|
209
|
+
bundle from the configured URL.
|
|
210
|
+
|
|
211
|
+
<!-- example: exported-grid -->
|
|
212
|
+
```python
|
|
213
|
+
import py3Dmol
|
|
214
|
+
|
|
215
|
+
xyz = "2\nCarbon monoxide\nC 0 0 0\nO 1.2 0 0\n"
|
|
216
|
+
view = py3Dmol.view(width=640, height=320, viewergrid=(1, 2), linked=False)
|
|
217
|
+
view.addModel(xyz, "xyz")
|
|
218
|
+
view.getModel(viewer=(0, 0)).setStyle({}, {"sphere": {"radius": 0.45, "color": "red"}})
|
|
219
|
+
view.getModel(viewer=(0, 1)).setStyle({}, {"stick": {"radius": 0.15, "color": "blue"}})
|
|
220
|
+
view.zoomTo()
|
|
221
|
+
html = view.write_html()
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Run `npm run test:examples:browser` from the repository root to exercise the grid
|
|
225
|
+
and both controls examples above with the local Python wrapper and JavaScript
|
|
226
|
+
bundles. The checks use Python's standard library and Chromium via the existing
|
|
227
|
+
Puppeteer dependency; they do not require Jupyter or network downloads. Run
|
|
228
|
+
`npm run test:python` for constructor validation and HTML serialization checks.
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
License
|
|
232
|
+
-------
|
|
233
|
+
|
|
234
|
+
MIT
|
py3dmol-3.0.0/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
py3Dmol
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
A simple [IPython/Jupyter](http://jupyter.org/) widget to
|
|
5
|
+
embed an interactive [3Dmol.js](http://3dmol.org) viewer in a notebook.
|
|
6
|
+
|
|
7
|
+
The widget emits HTML and JavaScript. Once displayed, it remains interactive
|
|
8
|
+
without a running IPython kernel, but communication is one-way: Python queues
|
|
9
|
+
commands for the browser and cannot read JavaScript return values or receive
|
|
10
|
+
viewer events. Exported pages still need JavaScript and WebGL enabled, plus access
|
|
11
|
+
to the configured library URL and any remotely loaded molecular data.
|
|
12
|
+
|
|
13
|
+
If you experience problems, please file
|
|
14
|
+
an [issue](https://github.com/3dmol/3Dmol.js/issues).
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[An example notebook](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/master/py3Dmol/examples.ipynb)
|
|
18
|
+
|
|
19
|
+
Installation
|
|
20
|
+
------------
|
|
21
|
+
|
|
22
|
+
From PyPI:
|
|
23
|
+
|
|
24
|
+
pip install py3Dmol
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Usage
|
|
28
|
+
-----
|
|
29
|
+
|
|
30
|
+
Open a notebook
|
|
31
|
+
|
|
32
|
+
jupyter notebook
|
|
33
|
+
|
|
34
|
+
and issue
|
|
35
|
+
|
|
36
|
+
```Python
|
|
37
|
+
import py3Dmol
|
|
38
|
+
view = py3Dmol.view(query='pdb:1ubq')
|
|
39
|
+
view.setStyle({'cartoon':{'color':'spectrum'}})
|
|
40
|
+
view
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
API
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
Use the [$3Dmol.GLViewer reference](https://3dmol.org/doc/GLViewer.html) for
|
|
47
|
+
method names and argument objects. The wrapper translates positional arguments
|
|
48
|
+
into JavaScript using JSON serialization; use Python dictionaries for selections
|
|
49
|
+
and styles, and Python `True`, `False`, and `None` for their JSON equivalents.
|
|
50
|
+
Python functions cannot be passed as JavaScript callbacks.
|
|
51
|
+
|
|
52
|
+
Most forwarded methods queue a command and return the Python `view` for chaining,
|
|
53
|
+
not the JavaScript result. For example, a forwarded `addModel` call does not return
|
|
54
|
+
a model object, and a forwarded `selectedAtoms` call does not return atoms to
|
|
55
|
+
Python. `getModel()` is a wrapper-specific exception: it returns a model proxy
|
|
56
|
+
whose methods queue calls to the JavaScript [GLModel](https://3dmol.org/doc/GLModel.html).
|
|
57
|
+
Promises and browser-side values do not cross back into Python.
|
|
58
|
+
|
|
59
|
+
Display and export helpers
|
|
60
|
+
--------------------------
|
|
61
|
+
|
|
62
|
+
| Operation | Python helper |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| Display a new viewer | Evaluate the view as the last notebook expression, or call `show()` |
|
|
65
|
+
| Apply queued commands to the displayed viewer | `update()` |
|
|
66
|
+
| Return embeddable HTML as a Python string | `write_html()` |
|
|
67
|
+
| Write an HTML page to a path or writable file object | `write_html(f)`; `fullpage=True` fills the page when writing a file |
|
|
68
|
+
| Display a still or animated image in notebook output | `png()` or `apng(nframes)` after the viewer has been displayed |
|
|
69
|
+
|
|
70
|
+
Repeated `show()` calls create new displays; subsequent `update()` calls target the
|
|
71
|
+
most recently displayed instance. Image helpers publish browser output rather
|
|
72
|
+
than returning image bytes to Python. Notebook output must allow the embedded
|
|
73
|
+
JavaScript to run; if the viewer fails to load, inspect the browser console.
|
|
74
|
+
|
|
75
|
+
Use `viewergrid=(rows, columns)` to create a grid. Forwarded commands apply to
|
|
76
|
+
every cell unless `viewer=(row, column)` selects one, with zero-based indices.
|
|
77
|
+
`getModel` requires an explicit `viewer` when a grid is enabled. Constructor
|
|
78
|
+
option `linked=True` links mouse controls across the grid.
|
|
79
|
+
|
|
80
|
+
The `js` constructor argument selects the 3Dmol.js bundle URL. Match that bundle
|
|
81
|
+
to the API documentation you use. The library is loaded once per page, so changing
|
|
82
|
+
`js` on a later view does not replace an already loaded library.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
Editing, trajectory, and classroom controls
|
|
86
|
+
-------------------------------------------
|
|
87
|
+
|
|
88
|
+
These optional constructor arguments enable browser controls in notebooks and
|
|
89
|
+
exported HTML. All three features are disabled by default.
|
|
90
|
+
|
|
91
|
+
| Argument | Behavior |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| `edit=True` | Show the edit button for models, styles, surfaces, volumes, and measurements |
|
|
94
|
+
| `trajectory=True` | Enable trajectory controls for models loaded with frames, such as through `addModelsAsFrames` |
|
|
95
|
+
| `learning=True` | Show the classroom button and session-name dialog |
|
|
96
|
+
| `learning={...}` | Configure the classroom with the options below |
|
|
97
|
+
| `ui_js="..."` | Override the optional UI bundle URL |
|
|
98
|
+
|
|
99
|
+
All views default to the same pinned 3Dmol.js release on jsDelivr, with or without
|
|
100
|
+
controls. The UI bundle loads automatically when any controls are requested;
|
|
101
|
+
its URL is the sibling `3Dmol.ui.js` or `3Dmol.ui-min.js` of the core `js` URL.
|
|
102
|
+
To use another release or a hosted build, set `js` explicitly and use matching
|
|
103
|
+
core and UI builds. For a custom core filename, supply `ui_js` explicitly.
|
|
104
|
+
Use the same bundle URLs for every view on a page: the first core and UI bundles
|
|
105
|
+
loaded are reused by later views. Restart the notebook output page to switch
|
|
106
|
+
bundles. The examples below use the default released bundles.
|
|
107
|
+
|
|
108
|
+
Controls apply to one viewer. Grids with more than one cell share a container and
|
|
109
|
+
canvas, so they cannot use these options; create separate `view` objects for
|
|
110
|
+
independent controls or classrooms. A `viewergrid=(1, 1)` is supported.
|
|
111
|
+
|
|
112
|
+
<!-- example: viewer-controls -->
|
|
113
|
+
```python
|
|
114
|
+
import py3Dmol
|
|
115
|
+
|
|
116
|
+
frames = ("2\nFrame 0\nC 0 0 0\nO 1.2 0 0\n"
|
|
117
|
+
"2\nFrame 1\nC 0 0 0\nO 1.5 0 0\n")
|
|
118
|
+
view = py3Dmol.view(width=640, height=400, edit=True, trajectory=True,
|
|
119
|
+
learning=True)
|
|
120
|
+
view.addModelsAsFrames(frames, "xyz")
|
|
121
|
+
view.setStyle({}, {"stick": {}, "sphere": {"scale": 0.3}})
|
|
122
|
+
view.zoomTo()
|
|
123
|
+
html = view.write_html()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Display `view` in a notebook, or save `html` to embed the same controls in a page.
|
|
127
|
+
Use the classroom button to create a session or join an existing one. Pass a
|
|
128
|
+
dictionary such as `learning={"mode": "button", "session": "my-class"}` to
|
|
129
|
+
prefill the session name. Browser edits and classroom events are not returned to
|
|
130
|
+
Python; `write_html()` exports the commands queued in Python, not subsequent
|
|
131
|
+
browser edits.
|
|
132
|
+
|
|
133
|
+
For hidden activation, set `mode` to `"hidden"` and provide a nonempty, unique
|
|
134
|
+
`session` identifier. Give every participant the same identifier and server.
|
|
135
|
+
The classroom button stays hidden while waiting. Focus the instructor's viewer
|
|
136
|
+
and press **Ctrl+Alt+I** to start; other active viewers with that configuration
|
|
137
|
+
automatically join as students, including viewers opened later.
|
|
138
|
+
|
|
139
|
+
<!-- example: hidden-classroom -->
|
|
140
|
+
```python
|
|
141
|
+
import py3Dmol
|
|
142
|
+
|
|
143
|
+
xyz = "2\nCarbon monoxide\nC 0 0 0\nO 1.2 0 0\n"
|
|
144
|
+
view = py3Dmol.view(width=640, height=400, data=xyz, format="xyz",
|
|
145
|
+
style={"sphere": {"scale": 0.3}, "stick": {}},
|
|
146
|
+
learning={"mode": "hidden", "session": "py3dmol-bonding-class-a"})
|
|
147
|
+
html = view.write_html()
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Replace the example session identifier with one unique to your class and viewer.
|
|
151
|
+
The instructor gets the usual editing, trajectory, and classroom controls.
|
|
152
|
+
Student editing and trajectory controls are disabled while following; students
|
|
153
|
+
can still rotate, zoom, and answer atom queries. A session ends when the
|
|
154
|
+
instructor leaves or closes their viewer.
|
|
155
|
+
|
|
156
|
+
The `learning` dictionary accepts the JSON options from
|
|
157
|
+
[`LearningConfig`](https://3dmol.org/doc/LearningConfig.html): `mode`, `session`,
|
|
158
|
+
`server`, `hotkey`, and `clientURL`. `server` defaults to `"https://3dmol.csb.pitt.edu"`;
|
|
159
|
+
set it to your session server's origin, including protocol and port when needed,
|
|
160
|
+
for example `"http://127.0.0.1:5072"`. `hotkey` changes the hidden activation
|
|
161
|
+
shortcut, and `clientURL` overrides the Socket.IO browser-client script. Python
|
|
162
|
+
callbacks, including `socketFactory` and adapter hooks, are not supported.
|
|
163
|
+
|
|
164
|
+
See the [learning-environment guide](https://github.com/3dmol/3Dmol.js/blob/master/tutorials/learning_environment.md)
|
|
165
|
+
for shared scene behavior, classroom controls, and server setup. Hidden mode
|
|
166
|
+
changes how controls appear; it does not authenticate instructors.
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
Export a grid with independent styles
|
|
170
|
+
------------------------------------
|
|
171
|
+
|
|
172
|
+
This example puts the same inline molecule in two cells, then styles each cell's
|
|
173
|
+
model separately. `addModel` and `zoomTo` target both cells; `getModel` selects one
|
|
174
|
+
cell. `write_html()` returns an HTML fragment that can be saved or embedded in a
|
|
175
|
+
page without an active notebook kernel. The fragment still loads the JavaScript
|
|
176
|
+
bundle from the configured URL.
|
|
177
|
+
|
|
178
|
+
<!-- example: exported-grid -->
|
|
179
|
+
```python
|
|
180
|
+
import py3Dmol
|
|
181
|
+
|
|
182
|
+
xyz = "2\nCarbon monoxide\nC 0 0 0\nO 1.2 0 0\n"
|
|
183
|
+
view = py3Dmol.view(width=640, height=320, viewergrid=(1, 2), linked=False)
|
|
184
|
+
view.addModel(xyz, "xyz")
|
|
185
|
+
view.getModel(viewer=(0, 0)).setStyle({}, {"sphere": {"radius": 0.45, "color": "red"}})
|
|
186
|
+
view.getModel(viewer=(0, 1)).setStyle({}, {"stick": {"radius": 0.15, "color": "blue"}})
|
|
187
|
+
view.zoomTo()
|
|
188
|
+
html = view.write_html()
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Run `npm run test:examples:browser` from the repository root to exercise the grid
|
|
192
|
+
and both controls examples above with the local Python wrapper and JavaScript
|
|
193
|
+
bundles. The checks use Python's standard library and Chromium via the existing
|
|
194
|
+
Puppeteer dependency; they do not require Jupyter or network downloads. Run
|
|
195
|
+
`npm run test:python` for constructor validation and HTML serialization checks.
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
License
|
|
199
|
+
-------
|
|
200
|
+
|
|
201
|
+
MIT
|
|
@@ -2,6 +2,7 @@ import time
|
|
|
2
2
|
import json
|
|
3
3
|
import sys
|
|
4
4
|
import re
|
|
5
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
5
6
|
|
|
6
7
|
try:
|
|
7
8
|
import IPython.display
|
|
@@ -40,31 +41,68 @@ def tostr(arg):
|
|
|
40
41
|
return json.dumps(arg.tolist()) #numpy arrays and torch tensor
|
|
41
42
|
|
|
42
43
|
class view(object):
|
|
43
|
-
'''
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
'''Construct HTML/JavaScript views for IPython notebooks and exported pages.
|
|
45
|
+
Displayed views remain interactive without a running kernel. Python queues
|
|
46
|
+
browser commands; JavaScript results and events are not returned to Python.
|
|
47
|
+
The page still needs JavaScript, WebGL, and any referenced network resources.
|
|
48
|
+
|
|
49
|
+
A viewergrid tuple (rows, columns) creates a grid sharing one canvas.
|
|
50
|
+
Commands apply to all cells unless viewer=(row, column) selects one cell
|
|
51
|
+
using zero-based indices. getModel requires a cell when a grid is enabled.
|
|
52
|
+
|
|
53
|
+
Forwarded methods use the GLViewer API with JSON-serializable positional
|
|
54
|
+
arguments and return this Python view for chaining, not JavaScript results.
|
|
55
|
+
getModel returns a proxy for queuing GLModel calls. Python callbacks and
|
|
56
|
+
browser-side promises are not supported across this one-way interface.
|
|
57
|
+
https://3dmol.org/doc/GLViewer.html
|
|
56
58
|
'''
|
|
57
|
-
def __init__(self,query='',width=640,height=480,viewergrid=None,data=None,style=None,linked=True,options=dict(),format=None,js=
|
|
59
|
+
def __init__(self,query='',width=640,height=480,viewergrid=None,data=None,style=None,linked=True,options=dict(),format=None,js=None,
|
|
60
|
+
edit=False,trajectory=False,learning=False,ui_js=None):
|
|
58
61
|
'''Create a 3Dmol.js view.
|
|
59
|
-
width -- width in pixels
|
|
60
|
-
height -- height in pixels
|
|
62
|
+
width -- container width in pixels (int) or a CSS dimension string
|
|
63
|
+
height -- container height in pixels (int) or a CSS dimension string
|
|
61
64
|
query -- optional argument to provide to $3Dmol.download
|
|
62
65
|
viewergrid -- optional tuple (rows,columns) to define grid
|
|
66
|
+
linked -- whether mouse controls affect all grid cells (default True)
|
|
63
67
|
data -- molecular data to provide to addModel, with viewer grid can be indexed (r,c)
|
|
64
68
|
format -- format of provided data
|
|
65
69
|
style -- style to apply, with viewer grid can be indexed (r,c)
|
|
66
70
|
options -- optional options to provide to $3Dmol.download or addModel
|
|
67
|
-
js --
|
|
71
|
+
js -- core bundle URL; defaults to the same pinned npm release for all
|
|
72
|
+
views, with or without controls. The first load wins.
|
|
73
|
+
edit -- show the edit-menu button (default False)
|
|
74
|
+
trajectory -- show trajectory controls when frames are present (default False)
|
|
75
|
+
learning -- True for a classroom button, or a LearningConfig dictionary;
|
|
76
|
+
hidden mode requires {'mode': 'hidden', 'session': 'unique-id'}.
|
|
77
|
+
The server defaults to https://3dmol.csb.pitt.edu.
|
|
78
|
+
ui_js -- optional UI bundle URL, otherwise inferred alongside js;
|
|
79
|
+
use matching core and UI builds when overriding either URL
|
|
80
|
+
Controls require a single viewer (viewergrid=(1,1) is also supported).
|
|
81
|
+
Python queues commands; classroom events do not call back into Python.'''
|
|
82
|
+
if not isinstance(learning, (bool, dict)):
|
|
83
|
+
raise TypeError('learning must be a boolean or a configuration dictionary')
|
|
84
|
+
if isinstance(learning, dict):
|
|
85
|
+
mode = learning.get('mode', 'button')
|
|
86
|
+
if mode not in ('button', 'hidden'):
|
|
87
|
+
raise ValueError("learning mode must be 'button' or 'hidden'")
|
|
88
|
+
session = learning.get('session')
|
|
89
|
+
if mode == 'hidden' and (not isinstance(session, str) or not session.strip()):
|
|
90
|
+
raise ValueError('Hidden classroom mode requires a nonblank session identifier')
|
|
91
|
+
has_ui = bool(edit or trajectory or learning is True or isinstance(learning, dict))
|
|
92
|
+
if has_ui and viewergrid and tuple(viewergrid) != (1, 1):
|
|
93
|
+
raise ValueError('Controls require a single viewer; use separate views instead of a multi-cell viewergrid')
|
|
94
|
+
if js is None:
|
|
95
|
+
js = 'https://cdn.jsdelivr.net/npm/3dmol@3.0.0/build/3Dmol-min.js'
|
|
96
|
+
if has_ui and ui_js is None:
|
|
97
|
+
parts = urlsplit(js)
|
|
98
|
+
path, matches = re.subn(r'(^|/)3Dmol(-min)?\.js$', r'\g<1>3Dmol.ui\g<2>.js', parts.path)
|
|
99
|
+
if not matches:
|
|
100
|
+
raise ValueError('Specify ui_js when js does not end in 3Dmol.js or 3Dmol-min.js')
|
|
101
|
+
ui_js = urlunsplit(parts._replace(path=path))
|
|
102
|
+
# These values live inside an inline script, not just a JavaScript string.
|
|
103
|
+
# Escape '<' so a session identifier or URL cannot close the script tag.
|
|
104
|
+
ui_config = json.dumps({'edit': bool(edit), 'trajectory': bool(trajectory),
|
|
105
|
+
'learning': learning}).replace('<', '\\u003c')
|
|
68
106
|
divid = "3dmolviewer_UNIQUEID"
|
|
69
107
|
warnid = "3dmolwarning_UNIQUEID"
|
|
70
108
|
self.uniqueid = None
|
|
@@ -100,25 +138,60 @@ var loadScriptAsync = function(uri){
|
|
|
100
138
|
module = savedmodule;
|
|
101
139
|
resolve();
|
|
102
140
|
};
|
|
141
|
+
tag.onerror = () => {
|
|
142
|
+
exports = savedexports;
|
|
143
|
+
module = savedmodule;
|
|
144
|
+
reject(new Error('Unable to load ' + uri));
|
|
145
|
+
};
|
|
103
146
|
var firstScriptTag = document.getElementsByTagName('script')[0];
|
|
104
147
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
|
105
148
|
});
|
|
106
149
|
};
|
|
107
150
|
|
|
108
151
|
if(typeof $3Dmolpromise === 'undefined') {
|
|
109
|
-
$3Dmolpromise =
|
|
110
|
-
$3Dmolpromise = loadScriptAsync('%s');
|
|
152
|
+
$3Dmolpromise = typeof $3Dmol === 'undefined' ? loadScriptAsync(%s) : Promise.resolve();
|
|
111
153
|
}
|
|
112
154
|
|
|
113
155
|
var viewer_UNIQUEID = null;
|
|
156
|
+
""" % json.dumps(js).replace('<', '\\u003c')
|
|
157
|
+
|
|
158
|
+
dependency = '$3Dmolpromise'
|
|
159
|
+
if has_ui:
|
|
160
|
+
self.startjs += """
|
|
161
|
+
if(typeof $3DmolUIpromise === 'undefined') {
|
|
162
|
+
$3DmolUIpromise = $3Dmolpromise.then(function() {
|
|
163
|
+
if (typeof $3Dmol.StateManager === 'function') return;
|
|
164
|
+
return loadScriptAsync(%s);
|
|
165
|
+
}).then(function() {
|
|
166
|
+
if (typeof $3Dmol.StateManager !== 'function') {
|
|
167
|
+
throw new Error('The UI bundle does not provide StateManager. Use matching core and UI builds.');
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
""" % json.dumps(ui_js).replace('<', '\\u003c')
|
|
172
|
+
dependency = '$3DmolUIpromise'
|
|
173
|
+
|
|
174
|
+
self.startjs += 'var viewer_ready_UNIQUEID = %s.then(function() {\n' % dependency
|
|
175
|
+
self.startjs += """
|
|
114
176
|
var warn = document.getElementById("%s");
|
|
115
177
|
if(warn) {
|
|
116
178
|
warn.parentNode.removeChild(warn);
|
|
117
179
|
}
|
|
118
|
-
""" %
|
|
119
|
-
|
|
120
|
-
self.
|
|
121
|
-
|
|
180
|
+
""" % warnid
|
|
181
|
+
|
|
182
|
+
self.endjs = '''});
|
|
183
|
+
viewer_ready_UNIQUEID.catch(function(error) {
|
|
184
|
+
var host = document.getElementById("%s");
|
|
185
|
+
if (host) {
|
|
186
|
+
var warning = document.getElementById("%s") || document.createElement('p');
|
|
187
|
+
warning.id = "%s";
|
|
188
|
+
warning.style.cssText = 'position:absolute;top:0;background:#ffcccc;color:black';
|
|
189
|
+
warning.textContent = '3Dmol.js failed to initialize: ' + error.message;
|
|
190
|
+
host.appendChild(warning);
|
|
191
|
+
}
|
|
192
|
+
console.error(error);
|
|
193
|
+
});
|
|
194
|
+
</script>''' % (divid, warnid, warnid)
|
|
122
195
|
self.viewergrid = None
|
|
123
196
|
|
|
124
197
|
if viewergrid: #create split view
|
|
@@ -134,11 +207,18 @@ if(warn) {
|
|
|
134
207
|
if viewergrid:
|
|
135
208
|
for r in range(viewergrid[0]):
|
|
136
209
|
for c in range(viewergrid[1]):
|
|
137
|
-
self.startjs += '$3Dmol.download(
|
|
138
|
-
self.endjs = "})
|
|
210
|
+
self.startjs += 'return $3Dmol.download(%s, viewergrid_UNIQUEID[%d][%d], %s).then(function() {\n' % (json.dumps(query),r,c,json.dumps(options))
|
|
211
|
+
self.endjs = "});\n" + self.endjs
|
|
139
212
|
else:
|
|
140
|
-
self.startjs += '$3Dmol.download(
|
|
141
|
-
self.endjs = "})
|
|
213
|
+
self.startjs += 'return $3Dmol.download(%s, viewer_UNIQUEID, %s).then(function() {\n' % (json.dumps(query),json.dumps(options))
|
|
214
|
+
self.endjs = "});\n" + self.endjs
|
|
215
|
+
|
|
216
|
+
finish = ''
|
|
217
|
+
if has_ui:
|
|
218
|
+
if learning is True or isinstance(learning, dict):
|
|
219
|
+
finish += "if (typeof $3Dmol.LearningSession !== 'function') throw new Error('This UI bundle does not support classrooms. Use matching current core and UI builds.');\n"
|
|
220
|
+
finish += 'new $3Dmol.StateManager(viewer_UNIQUEID, %s);\n' % ui_config
|
|
221
|
+
self.endjs = finish + 'return viewer_UNIQUEID;\n' + self.endjs
|
|
142
222
|
|
|
143
223
|
if viewergrid:
|
|
144
224
|
for r in range(viewergrid[0]):
|
|
@@ -211,19 +291,22 @@ if(warn) {
|
|
|
211
291
|
if self.uniqueid == None:
|
|
212
292
|
script = self._make_html()
|
|
213
293
|
script += '''<script>
|
|
214
|
-
|
|
294
|
+
viewer_ready_%s.then(function() { //wait for this view's scene and controls
|
|
215
295
|
%s
|
|
216
296
|
viewer_%s.render();
|
|
297
|
+
if (viewer_%s.ui) viewer_%s.ui.refresh();
|
|
217
298
|
});
|
|
218
|
-
</script>''' % (self.updatejs.replace('UNIQUEID',self.uniqueid),self.uniqueid)
|
|
299
|
+
</script>''' % (self.uniqueid,self.updatejs.replace('UNIQUEID',self.uniqueid),self.uniqueid,self.uniqueid,self.uniqueid)
|
|
219
300
|
self.updatejs = ''
|
|
220
301
|
return IPython.display.publish_display_data({'application/3dmoljs_load.v0':script, 'text/html': script},metadata={})
|
|
221
302
|
|
|
222
303
|
|
|
223
304
|
def write_html(self, f=None, fullpage=False):
|
|
224
|
-
'''
|
|
225
|
-
f -- file name (str) or
|
|
226
|
-
fullpage -- instead of
|
|
305
|
+
'''Export the queued scene as HTML without requiring notebook display.
|
|
306
|
+
f -- file name (str) or writable file object; omitted returns an HTML fragment
|
|
307
|
+
fullpage -- fill the page instead of using the configured size when writing f;
|
|
308
|
+
this option is not applied when returning a string
|
|
309
|
+
Referenced scripts and remote molecular data are not embedded by this method.
|
|
227
310
|
'''
|
|
228
311
|
|
|
229
312
|
if f == None:
|
|
@@ -246,25 +329,33 @@ if(warn) {
|
|
|
246
329
|
|
|
247
330
|
@using_ipython
|
|
248
331
|
def png(self):
|
|
249
|
-
'''
|
|
332
|
+
'''Display a PNG of an already instantiated viewer in notebook output.
|
|
333
|
+
The image is generated in the browser; no image bytes are returned to Python.
|
|
334
|
+
'''
|
|
250
335
|
if not self.uniqueid:
|
|
251
336
|
raise AssertionError('Must instantiate viewer before generating image.')
|
|
252
337
|
script = '''<img id="img_{0}">
|
|
253
338
|
<script>
|
|
339
|
+
viewer_ready_{0}.then(function() {{
|
|
254
340
|
var png = viewer_{0}.pngURI()
|
|
255
341
|
document.getElementById('img_{0}').src = png;
|
|
342
|
+
}});
|
|
256
343
|
</script>'''.format(self.uniqueid)
|
|
257
344
|
return IPython.display.publish_display_data({'application/3dmoljs_load.v0':script, 'text/html': script},metadata={})
|
|
258
345
|
|
|
259
346
|
@using_ipython
|
|
260
347
|
def apng(self, nframes=1):
|
|
261
|
-
'''
|
|
348
|
+
'''Display an APNG of an already instantiated viewer in notebook output.
|
|
349
|
+
Capture nframes rendered changes; no image bytes are returned to Python.
|
|
350
|
+
'''
|
|
262
351
|
if not self.uniqueid:
|
|
263
352
|
raise AssertionError('Must instantiate viewer before generating animated image.')
|
|
264
353
|
script = '''<img id="img_{0}">
|
|
265
354
|
<script>
|
|
355
|
+
viewer_ready_{0}.then(function() {{
|
|
266
356
|
viewer_{0}.apngURI({1}).then(png => {{
|
|
267
357
|
document.getElementById('img_{0}').src = png; }});
|
|
358
|
+
}});
|
|
268
359
|
</script>'''.format(self.uniqueid,nframes)
|
|
269
360
|
return IPython.display.publish_display_data({'application/3dmoljs_load.v0':script, 'text/html': script},metadata={})
|
|
270
361
|
|
|
@@ -292,6 +383,10 @@ if(warn) {
|
|
|
292
383
|
return makejs #return from getattr
|
|
293
384
|
|
|
294
385
|
def getModel(self,*args,**kwargs):
|
|
386
|
+
"""Return a proxy for queuing GLModel methods, not its atom data.
|
|
387
|
+
Positional arguments are forwarded to GLViewer.getModel. With a viewer grid,
|
|
388
|
+
viewer=(row, column) is required. Proxy calls return the parent Python view.
|
|
389
|
+
"""
|
|
295
390
|
if self.viewergrid:
|
|
296
391
|
if kwargs and 'viewer' in kwargs:
|
|
297
392
|
coords = kwargs['viewer']
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py3Dmol
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: An IPython interface for embedding 3Dmol.js views in Jupyter notebooks
|
|
5
|
+
Home-page: https://3dmol.org
|
|
6
|
+
Author: David Koes
|
|
7
|
+
Author-email: dkoes@pitt.edu
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: molecule protein visualization
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
Provides-Extra: ipython
|
|
21
|
+
Requires-Dist: IPython; extra == "ipython"
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description
|
|
26
|
+
Dynamic: description-content-type
|
|
27
|
+
Dynamic: home-page
|
|
28
|
+
Dynamic: keywords
|
|
29
|
+
Dynamic: license
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
Dynamic: provides-extra
|
|
32
|
+
Dynamic: summary
|
|
33
|
+
|
|
34
|
+
py3Dmol
|
|
35
|
+
=======
|
|
36
|
+
|
|
37
|
+
A simple [IPython/Jupyter](http://jupyter.org/) widget to
|
|
38
|
+
embed an interactive [3Dmol.js](http://3dmol.org) viewer in a notebook.
|
|
39
|
+
|
|
40
|
+
The widget emits HTML and JavaScript. Once displayed, it remains interactive
|
|
41
|
+
without a running IPython kernel, but communication is one-way: Python queues
|
|
42
|
+
commands for the browser and cannot read JavaScript return values or receive
|
|
43
|
+
viewer events. Exported pages still need JavaScript and WebGL enabled, plus access
|
|
44
|
+
to the configured library URL and any remotely loaded molecular data.
|
|
45
|
+
|
|
46
|
+
If you experience problems, please file
|
|
47
|
+
an [issue](https://github.com/3dmol/3Dmol.js/issues).
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
[An example notebook](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/master/py3Dmol/examples.ipynb)
|
|
51
|
+
|
|
52
|
+
Installation
|
|
53
|
+
------------
|
|
54
|
+
|
|
55
|
+
From PyPI:
|
|
56
|
+
|
|
57
|
+
pip install py3Dmol
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Usage
|
|
61
|
+
-----
|
|
62
|
+
|
|
63
|
+
Open a notebook
|
|
64
|
+
|
|
65
|
+
jupyter notebook
|
|
66
|
+
|
|
67
|
+
and issue
|
|
68
|
+
|
|
69
|
+
```Python
|
|
70
|
+
import py3Dmol
|
|
71
|
+
view = py3Dmol.view(query='pdb:1ubq')
|
|
72
|
+
view.setStyle({'cartoon':{'color':'spectrum'}})
|
|
73
|
+
view
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
API
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
Use the [$3Dmol.GLViewer reference](https://3dmol.org/doc/GLViewer.html) for
|
|
80
|
+
method names and argument objects. The wrapper translates positional arguments
|
|
81
|
+
into JavaScript using JSON serialization; use Python dictionaries for selections
|
|
82
|
+
and styles, and Python `True`, `False`, and `None` for their JSON equivalents.
|
|
83
|
+
Python functions cannot be passed as JavaScript callbacks.
|
|
84
|
+
|
|
85
|
+
Most forwarded methods queue a command and return the Python `view` for chaining,
|
|
86
|
+
not the JavaScript result. For example, a forwarded `addModel` call does not return
|
|
87
|
+
a model object, and a forwarded `selectedAtoms` call does not return atoms to
|
|
88
|
+
Python. `getModel()` is a wrapper-specific exception: it returns a model proxy
|
|
89
|
+
whose methods queue calls to the JavaScript [GLModel](https://3dmol.org/doc/GLModel.html).
|
|
90
|
+
Promises and browser-side values do not cross back into Python.
|
|
91
|
+
|
|
92
|
+
Display and export helpers
|
|
93
|
+
--------------------------
|
|
94
|
+
|
|
95
|
+
| Operation | Python helper |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| Display a new viewer | Evaluate the view as the last notebook expression, or call `show()` |
|
|
98
|
+
| Apply queued commands to the displayed viewer | `update()` |
|
|
99
|
+
| Return embeddable HTML as a Python string | `write_html()` |
|
|
100
|
+
| Write an HTML page to a path or writable file object | `write_html(f)`; `fullpage=True` fills the page when writing a file |
|
|
101
|
+
| Display a still or animated image in notebook output | `png()` or `apng(nframes)` after the viewer has been displayed |
|
|
102
|
+
|
|
103
|
+
Repeated `show()` calls create new displays; subsequent `update()` calls target the
|
|
104
|
+
most recently displayed instance. Image helpers publish browser output rather
|
|
105
|
+
than returning image bytes to Python. Notebook output must allow the embedded
|
|
106
|
+
JavaScript to run; if the viewer fails to load, inspect the browser console.
|
|
107
|
+
|
|
108
|
+
Use `viewergrid=(rows, columns)` to create a grid. Forwarded commands apply to
|
|
109
|
+
every cell unless `viewer=(row, column)` selects one, with zero-based indices.
|
|
110
|
+
`getModel` requires an explicit `viewer` when a grid is enabled. Constructor
|
|
111
|
+
option `linked=True` links mouse controls across the grid.
|
|
112
|
+
|
|
113
|
+
The `js` constructor argument selects the 3Dmol.js bundle URL. Match that bundle
|
|
114
|
+
to the API documentation you use. The library is loaded once per page, so changing
|
|
115
|
+
`js` on a later view does not replace an already loaded library.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
Editing, trajectory, and classroom controls
|
|
119
|
+
-------------------------------------------
|
|
120
|
+
|
|
121
|
+
These optional constructor arguments enable browser controls in notebooks and
|
|
122
|
+
exported HTML. All three features are disabled by default.
|
|
123
|
+
|
|
124
|
+
| Argument | Behavior |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `edit=True` | Show the edit button for models, styles, surfaces, volumes, and measurements |
|
|
127
|
+
| `trajectory=True` | Enable trajectory controls for models loaded with frames, such as through `addModelsAsFrames` |
|
|
128
|
+
| `learning=True` | Show the classroom button and session-name dialog |
|
|
129
|
+
| `learning={...}` | Configure the classroom with the options below |
|
|
130
|
+
| `ui_js="..."` | Override the optional UI bundle URL |
|
|
131
|
+
|
|
132
|
+
All views default to the same pinned 3Dmol.js release on jsDelivr, with or without
|
|
133
|
+
controls. The UI bundle loads automatically when any controls are requested;
|
|
134
|
+
its URL is the sibling `3Dmol.ui.js` or `3Dmol.ui-min.js` of the core `js` URL.
|
|
135
|
+
To use another release or a hosted build, set `js` explicitly and use matching
|
|
136
|
+
core and UI builds. For a custom core filename, supply `ui_js` explicitly.
|
|
137
|
+
Use the same bundle URLs for every view on a page: the first core and UI bundles
|
|
138
|
+
loaded are reused by later views. Restart the notebook output page to switch
|
|
139
|
+
bundles. The examples below use the default released bundles.
|
|
140
|
+
|
|
141
|
+
Controls apply to one viewer. Grids with more than one cell share a container and
|
|
142
|
+
canvas, so they cannot use these options; create separate `view` objects for
|
|
143
|
+
independent controls or classrooms. A `viewergrid=(1, 1)` is supported.
|
|
144
|
+
|
|
145
|
+
<!-- example: viewer-controls -->
|
|
146
|
+
```python
|
|
147
|
+
import py3Dmol
|
|
148
|
+
|
|
149
|
+
frames = ("2\nFrame 0\nC 0 0 0\nO 1.2 0 0\n"
|
|
150
|
+
"2\nFrame 1\nC 0 0 0\nO 1.5 0 0\n")
|
|
151
|
+
view = py3Dmol.view(width=640, height=400, edit=True, trajectory=True,
|
|
152
|
+
learning=True)
|
|
153
|
+
view.addModelsAsFrames(frames, "xyz")
|
|
154
|
+
view.setStyle({}, {"stick": {}, "sphere": {"scale": 0.3}})
|
|
155
|
+
view.zoomTo()
|
|
156
|
+
html = view.write_html()
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Display `view` in a notebook, or save `html` to embed the same controls in a page.
|
|
160
|
+
Use the classroom button to create a session or join an existing one. Pass a
|
|
161
|
+
dictionary such as `learning={"mode": "button", "session": "my-class"}` to
|
|
162
|
+
prefill the session name. Browser edits and classroom events are not returned to
|
|
163
|
+
Python; `write_html()` exports the commands queued in Python, not subsequent
|
|
164
|
+
browser edits.
|
|
165
|
+
|
|
166
|
+
For hidden activation, set `mode` to `"hidden"` and provide a nonempty, unique
|
|
167
|
+
`session` identifier. Give every participant the same identifier and server.
|
|
168
|
+
The classroom button stays hidden while waiting. Focus the instructor's viewer
|
|
169
|
+
and press **Ctrl+Alt+I** to start; other active viewers with that configuration
|
|
170
|
+
automatically join as students, including viewers opened later.
|
|
171
|
+
|
|
172
|
+
<!-- example: hidden-classroom -->
|
|
173
|
+
```python
|
|
174
|
+
import py3Dmol
|
|
175
|
+
|
|
176
|
+
xyz = "2\nCarbon monoxide\nC 0 0 0\nO 1.2 0 0\n"
|
|
177
|
+
view = py3Dmol.view(width=640, height=400, data=xyz, format="xyz",
|
|
178
|
+
style={"sphere": {"scale": 0.3}, "stick": {}},
|
|
179
|
+
learning={"mode": "hidden", "session": "py3dmol-bonding-class-a"})
|
|
180
|
+
html = view.write_html()
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Replace the example session identifier with one unique to your class and viewer.
|
|
184
|
+
The instructor gets the usual editing, trajectory, and classroom controls.
|
|
185
|
+
Student editing and trajectory controls are disabled while following; students
|
|
186
|
+
can still rotate, zoom, and answer atom queries. A session ends when the
|
|
187
|
+
instructor leaves or closes their viewer.
|
|
188
|
+
|
|
189
|
+
The `learning` dictionary accepts the JSON options from
|
|
190
|
+
[`LearningConfig`](https://3dmol.org/doc/LearningConfig.html): `mode`, `session`,
|
|
191
|
+
`server`, `hotkey`, and `clientURL`. `server` defaults to `"https://3dmol.csb.pitt.edu"`;
|
|
192
|
+
set it to your session server's origin, including protocol and port when needed,
|
|
193
|
+
for example `"http://127.0.0.1:5072"`. `hotkey` changes the hidden activation
|
|
194
|
+
shortcut, and `clientURL` overrides the Socket.IO browser-client script. Python
|
|
195
|
+
callbacks, including `socketFactory` and adapter hooks, are not supported.
|
|
196
|
+
|
|
197
|
+
See the [learning-environment guide](https://github.com/3dmol/3Dmol.js/blob/master/tutorials/learning_environment.md)
|
|
198
|
+
for shared scene behavior, classroom controls, and server setup. Hidden mode
|
|
199
|
+
changes how controls appear; it does not authenticate instructors.
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
Export a grid with independent styles
|
|
203
|
+
------------------------------------
|
|
204
|
+
|
|
205
|
+
This example puts the same inline molecule in two cells, then styles each cell's
|
|
206
|
+
model separately. `addModel` and `zoomTo` target both cells; `getModel` selects one
|
|
207
|
+
cell. `write_html()` returns an HTML fragment that can be saved or embedded in a
|
|
208
|
+
page without an active notebook kernel. The fragment still loads the JavaScript
|
|
209
|
+
bundle from the configured URL.
|
|
210
|
+
|
|
211
|
+
<!-- example: exported-grid -->
|
|
212
|
+
```python
|
|
213
|
+
import py3Dmol
|
|
214
|
+
|
|
215
|
+
xyz = "2\nCarbon monoxide\nC 0 0 0\nO 1.2 0 0\n"
|
|
216
|
+
view = py3Dmol.view(width=640, height=320, viewergrid=(1, 2), linked=False)
|
|
217
|
+
view.addModel(xyz, "xyz")
|
|
218
|
+
view.getModel(viewer=(0, 0)).setStyle({}, {"sphere": {"radius": 0.45, "color": "red"}})
|
|
219
|
+
view.getModel(viewer=(0, 1)).setStyle({}, {"stick": {"radius": 0.15, "color": "blue"}})
|
|
220
|
+
view.zoomTo()
|
|
221
|
+
html = view.write_html()
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Run `npm run test:examples:browser` from the repository root to exercise the grid
|
|
225
|
+
and both controls examples above with the local Python wrapper and JavaScript
|
|
226
|
+
bundles. The checks use Python's standard library and Chromium via the existing
|
|
227
|
+
Puppeteer dependency; they do not require Jupyter or network downloads. Run
|
|
228
|
+
`npm run test:python` for constructor validation and HTML serialization checks.
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
License
|
|
232
|
+
-------
|
|
233
|
+
|
|
234
|
+
MIT
|
|
@@ -24,11 +24,11 @@ setup(
|
|
|
24
24
|
# the version across setup.py and the project code, see
|
|
25
25
|
# https://packaging.python.org/en/latest/single_source_version.html
|
|
26
26
|
# Keep version in synce with 3Dmol.js version. Use "postX" suffix if needed
|
|
27
|
-
version='
|
|
27
|
+
version='3.0.0',
|
|
28
28
|
|
|
29
29
|
description='An IPython interface for embedding 3Dmol.js views in Jupyter notebooks',
|
|
30
30
|
long_description=long_description,
|
|
31
|
-
|
|
31
|
+
long_description_content_type='text/markdown',
|
|
32
32
|
# The project's main homepage.
|
|
33
33
|
url='https://3dmol.org',
|
|
34
34
|
|
|
@@ -59,7 +59,6 @@ setup(
|
|
|
59
59
|
|
|
60
60
|
# Specify the Python versions you support here. In particular, ensure
|
|
61
61
|
# that you indicate whether you support Python 2, Python 3 or both.
|
|
62
|
-
'Programming Language :: Python :: 2',
|
|
63
62
|
'Programming Language :: Python :: 3',
|
|
64
63
|
|
|
65
64
|
],
|
py3dmol-2.5.4/PKG-INFO
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: py3Dmol
|
|
3
|
-
Version: 2.5.4
|
|
4
|
-
Summary: An IPython interface for embedding 3Dmol.js views in Jupyter notebooks
|
|
5
|
-
Home-page: https://3dmol.org
|
|
6
|
-
Author: David Koes
|
|
7
|
-
Author-email: dkoes@pitt.edu
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: molecule protein visualization
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Intended Audience :: Science/Research
|
|
13
|
-
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
14
|
-
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
16
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
-
Classifier: Programming Language :: Python :: 2
|
|
18
|
-
Classifier: Programming Language :: Python :: 3
|
|
19
|
-
License-File: LICENSE.txt
|
|
20
|
-
Provides-Extra: ipython
|
|
21
|
-
Requires-Dist: IPython; extra == "ipython"
|
|
22
|
-
Dynamic: author
|
|
23
|
-
Dynamic: author-email
|
|
24
|
-
Dynamic: classifier
|
|
25
|
-
Dynamic: description
|
|
26
|
-
Dynamic: home-page
|
|
27
|
-
Dynamic: keywords
|
|
28
|
-
Dynamic: license
|
|
29
|
-
Dynamic: license-file
|
|
30
|
-
Dynamic: provides-extra
|
|
31
|
-
Dynamic: summary
|
|
32
|
-
|
|
33
|
-
py3Dmol
|
|
34
|
-
=======
|
|
35
|
-
|
|
36
|
-
A simple [IPython/Jupyter](http://jupyter.org/) widget to
|
|
37
|
-
embed an interactive [3Dmol.js](http://3dmol.org) viewer in a notebook.
|
|
38
|
-
|
|
39
|
-
The widget is completely static, which means the viewer doesn't need a running
|
|
40
|
-
IPython kernel to be useful and web pages and presentations generated from
|
|
41
|
-
the notebook will work as expected. However, this also means there is only
|
|
42
|
-
one-way communication between the notebook and the viewer.
|
|
43
|
-
|
|
44
|
-
If you experience problems, please file
|
|
45
|
-
an [issue](https://github.com/3dmol/3Dmol.js/issues).
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
[An example notebook](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/master/py3Dmol/examples.ipynb)
|
|
49
|
-
|
|
50
|
-
Installation
|
|
51
|
-
------------
|
|
52
|
-
|
|
53
|
-
From PyPI:
|
|
54
|
-
|
|
55
|
-
pip install py3Dmol
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Usage
|
|
59
|
-
-----
|
|
60
|
-
|
|
61
|
-
Open a notebook
|
|
62
|
-
|
|
63
|
-
jupyter notebook
|
|
64
|
-
|
|
65
|
-
and issue
|
|
66
|
-
|
|
67
|
-
```Python
|
|
68
|
-
import py3Dmol
|
|
69
|
-
view = py3Dmol.view(query='pdb:1ubq')
|
|
70
|
-
view.setStyle({'cartoon':{'color':'spectrum'}})
|
|
71
|
-
view
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
API
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
The returned view object has the exact same API as [$3Dmol.GLViewer](https://3dmol.org/doc/GLViewer.html)
|
|
78
|
-
with the exception that functions return None.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
License
|
|
82
|
-
-------
|
|
83
|
-
|
|
84
|
-
MIT
|
py3dmol-2.5.4/README.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
py3Dmol
|
|
2
|
-
=======
|
|
3
|
-
|
|
4
|
-
A simple [IPython/Jupyter](http://jupyter.org/) widget to
|
|
5
|
-
embed an interactive [3Dmol.js](http://3dmol.org) viewer in a notebook.
|
|
6
|
-
|
|
7
|
-
The widget is completely static, which means the viewer doesn't need a running
|
|
8
|
-
IPython kernel to be useful and web pages and presentations generated from
|
|
9
|
-
the notebook will work as expected. However, this also means there is only
|
|
10
|
-
one-way communication between the notebook and the viewer.
|
|
11
|
-
|
|
12
|
-
If you experience problems, please file
|
|
13
|
-
an [issue](https://github.com/3dmol/3Dmol.js/issues).
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[An example notebook](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/master/py3Dmol/examples.ipynb)
|
|
17
|
-
|
|
18
|
-
Installation
|
|
19
|
-
------------
|
|
20
|
-
|
|
21
|
-
From PyPI:
|
|
22
|
-
|
|
23
|
-
pip install py3Dmol
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Usage
|
|
27
|
-
-----
|
|
28
|
-
|
|
29
|
-
Open a notebook
|
|
30
|
-
|
|
31
|
-
jupyter notebook
|
|
32
|
-
|
|
33
|
-
and issue
|
|
34
|
-
|
|
35
|
-
```Python
|
|
36
|
-
import py3Dmol
|
|
37
|
-
view = py3Dmol.view(query='pdb:1ubq')
|
|
38
|
-
view.setStyle({'cartoon':{'color':'spectrum'}})
|
|
39
|
-
view
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
API
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
The returned view object has the exact same API as [$3Dmol.GLViewer](https://3dmol.org/doc/GLViewer.html)
|
|
46
|
-
with the exception that functions return None.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
License
|
|
50
|
-
-------
|
|
51
|
-
|
|
52
|
-
MIT
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: py3Dmol
|
|
3
|
-
Version: 2.5.4
|
|
4
|
-
Summary: An IPython interface for embedding 3Dmol.js views in Jupyter notebooks
|
|
5
|
-
Home-page: https://3dmol.org
|
|
6
|
-
Author: David Koes
|
|
7
|
-
Author-email: dkoes@pitt.edu
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: molecule protein visualization
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Intended Audience :: Science/Research
|
|
13
|
-
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
14
|
-
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
16
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
-
Classifier: Programming Language :: Python :: 2
|
|
18
|
-
Classifier: Programming Language :: Python :: 3
|
|
19
|
-
License-File: LICENSE.txt
|
|
20
|
-
Provides-Extra: ipython
|
|
21
|
-
Requires-Dist: IPython; extra == "ipython"
|
|
22
|
-
Dynamic: author
|
|
23
|
-
Dynamic: author-email
|
|
24
|
-
Dynamic: classifier
|
|
25
|
-
Dynamic: description
|
|
26
|
-
Dynamic: home-page
|
|
27
|
-
Dynamic: keywords
|
|
28
|
-
Dynamic: license
|
|
29
|
-
Dynamic: license-file
|
|
30
|
-
Dynamic: provides-extra
|
|
31
|
-
Dynamic: summary
|
|
32
|
-
|
|
33
|
-
py3Dmol
|
|
34
|
-
=======
|
|
35
|
-
|
|
36
|
-
A simple [IPython/Jupyter](http://jupyter.org/) widget to
|
|
37
|
-
embed an interactive [3Dmol.js](http://3dmol.org) viewer in a notebook.
|
|
38
|
-
|
|
39
|
-
The widget is completely static, which means the viewer doesn't need a running
|
|
40
|
-
IPython kernel to be useful and web pages and presentations generated from
|
|
41
|
-
the notebook will work as expected. However, this also means there is only
|
|
42
|
-
one-way communication between the notebook and the viewer.
|
|
43
|
-
|
|
44
|
-
If you experience problems, please file
|
|
45
|
-
an [issue](https://github.com/3dmol/3Dmol.js/issues).
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
[An example notebook](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/master/py3Dmol/examples.ipynb)
|
|
49
|
-
|
|
50
|
-
Installation
|
|
51
|
-
------------
|
|
52
|
-
|
|
53
|
-
From PyPI:
|
|
54
|
-
|
|
55
|
-
pip install py3Dmol
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Usage
|
|
59
|
-
-----
|
|
60
|
-
|
|
61
|
-
Open a notebook
|
|
62
|
-
|
|
63
|
-
jupyter notebook
|
|
64
|
-
|
|
65
|
-
and issue
|
|
66
|
-
|
|
67
|
-
```Python
|
|
68
|
-
import py3Dmol
|
|
69
|
-
view = py3Dmol.view(query='pdb:1ubq')
|
|
70
|
-
view.setStyle({'cartoon':{'color':'spectrum'}})
|
|
71
|
-
view
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
API
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
The returned view object has the exact same API as [$3Dmol.GLViewer](https://3dmol.org/doc/GLViewer.html)
|
|
78
|
-
with the exception that functions return None.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
License
|
|
82
|
-
-------
|
|
83
|
-
|
|
84
|
-
MIT
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|