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

Updating JSMEEditor to work with Panel 1 / Bokeh 3 #42

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
finalize hoxbro contrib
MarcSkovMadsen committed Nov 12, 2023
commit fb11380ebcce085c100d53f4bdfcd438f21bf55f
1,354 changes: 1,341 additions & 13 deletions examples/reference/JSMEEditor.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -84,11 +84,12 @@ exclude = []
[[tool.mypy.overrides]]
module = [
"bokeh.*",
"comm.*",
"holoviews.*",
"hvplot.*",
"param",
"pyviz_comms",
"py3Dmol",
"pyviz_comms",
]
ignore_missing_imports = true

4 changes: 2 additions & 2 deletions src/panel_chemistry/bokeh_extensions/jsme_editor.py
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ class JSMEEditor(HTMLBox): # pylint: disable=too-few-public-methods,too-many-an

value = String(default="N[C@@H](CCC(=O)N[C@@H](CS)C(=O)NCC(=O)O)C(=O)O")
format = String(default="smiles")
subscriptions = List(String, default=[])
options = List(String, default=[])
subscriptions = List(String, default=[]) # type: ignore
options = List(String, default=[]) # type: ignore

jme = String(default="")
smiles = String(default="")
23 changes: 2 additions & 21 deletions src/panel_chemistry/bokeh_extensions/jsme_editor.ts
Original file line number Diff line number Diff line change
@@ -24,12 +24,9 @@ function readSDFValue(jsmeElement: any) {
}

function setModelValue(model: JSMEEditor, jsmeElement: any){
console.log("setValue - start", model.value)
var value = model.value
if (model.format==="smiles"){
console.log("getting smiles")
value = jsmeElement.smiles()
console.log("got smiles")
} else if (model.format==="mol"){
value = jsmeElement.molFile(false)
} else if (model.format==="mol3000"){
@@ -40,17 +37,13 @@ function setModelValue(model: JSMEEditor, jsmeElement: any){
value = jsmeElement.jmeFile()
}
if (model.value!==value && value!==null){
console.log("setting value", value)
model.value = value
}
console.log("setValue - end", model.value)
}

function setModelValues(model: JSMEEditor, jsmeElement: any){
console.log("setValues - start")
setModelValue(model, jsmeElement)
setOtherModelValues(model, jsmeElement)
console.log("setValues - end")
setOtherModelValues(model, jsmeElement)
}

function resetOtherModelValues(model: JSMEEditor, jsmeElement: any){
@@ -72,13 +65,11 @@ function cleanValue(value: any){
}

function setOtherModelValues(model: JSMEEditor, jsmeElement: any){
console.log("setOtherValues - start")
if (model.subscriptions.includes("jme")){model.jme = cleanValue(jsmeElement.jmeFile())}
if (model.subscriptions.includes("smiles")){model.smiles = cleanValue(jsmeElement.smiles())}
if (model.subscriptions.includes("mol")){model.mol = cleanValue(jsmeElement.molFile(false))}
if (model.subscriptions.includes("mol3000")){model.mol3000 = cleanValue(jsmeElement.molFile(true))}
if (model.subscriptions.includes("sdf")){model.sdf = cleanValue(readSDFValue(jsmeElement))}
console.log("setOtherValues - end")
}

// The view of the Bokeh extension/ HTML element
@@ -103,7 +94,6 @@ export class JSMEEditorView extends HTMLBoxView {
super.connect_signals()

this.connect(this.model.properties.value.change, () => {
console.log("value change", this.model.value)
if (!this.valueChanging){
if (this.model.value===""){
this.jsmeElement.reset()
@@ -113,25 +103,20 @@ export class JSMEEditorView extends HTMLBoxView {
}
})
this.connect(this.model.properties.format.change, () => {
console.log("format change", this.model.format)
setModelValue(this.model, this.jsmeElement);
})
this.connect(this.model.properties.subscriptions.change, () => {
console.log("subscriptions change", this.model.subscriptions)
resetOtherModelValues(this.model, this.jsmeElement);
})
this.connect(this.model.properties.options.change, () => {
console.log("options change", this.model.options)
this.setJSMEOptions()
})
this.connect(this.model.properties.guicolor.change, () => {
console.log("options change", this.model.options)
this.setGUIColor()
})
}

render(): void {
console.log("render - start")
super.render()
const id = "jsme-" + uuidv4()
const el = div({
@@ -161,8 +146,7 @@ export class JSMEEditorView extends HTMLBoxView {
setModelValues(this.model, this.jsmeElement)

const this_ = this;
function showEvent(event: any){
console.log("event", event)
function showEvent(_: any){
this_.valueChanging = true
setModelValues(this_.model, this_.jsmeElement)
this_.valueChanging = false
@@ -174,17 +158,14 @@ export class JSMEEditorView extends HTMLBoxView {
this.shadow_el.appendChild(this.container)

this._intialized = true
console.log("render - end")
}

setGUIColor(){
console.log("setGUIColor", this.model.guicolor)
this.jsmeElement.setUserInterfaceBackgroundColor(this.model.guicolor)
}

setJSMEOptions(){
const options = this.model.options.join(",")
console.log("setJSMEOptions", options)
this.jsmeElement.options(options)
}

6 changes: 3 additions & 3 deletions src/panel_chemistry/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/panel_chemistry/pane/py3dmol_viewer.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
try:
import py3Dmol
except ModuleNotFoundError:
# pylint: disable=invalid-name
# pylint: disable=invalid-name, too-few-public-methods
class py3Dmol(param.Parameterized): # type: ignore
"""Dummy py3Dmol class"""