def load_display_numpy(): global first ctx.array = cell("array") ctx.title = cell("str").set("Numpy array") ctx.aspect_layout = pythoncell().fromfile("AspectLayout.py") if first: ctx.registrar.python.register( ctx.aspect_layout ) #TODO: should be harmless to register same item twice ctx.display_numpy = reactor({ "array": { "pin": "input", "dtype": "array" }, "title": { "pin": "input", "dtype": "str" }, }) ctx.registrar.python.connect("AspectLayout", ctx.display_numpy) ctx.array.connect(ctx.display_numpy.array) ctx.title.connect(ctx.display_numpy.title) ctx.display_numpy.code_update.set("update()") ctx.display_numpy.code_stop.set("destroy()") ctx.code = pythoncell() ctx.code.connect(ctx.display_numpy.code_start) ctx.code.fromfile("cell-display-numpy.py") first = False
def load_display_numpy(): global first ctx.array = cell("array") ctx.title = cell("str").set("Numpy array") ctx.aspect_layout = pythoncell().fromfile("AspectLayout.py") if first: ctx.registrar.python.register(ctx.aspect_layout) #TODO: should be harmless to register same item twice ctx.display_numpy = reactor({ "array": {"pin": "input", "dtype": "array"}, "title": {"pin": "input", "dtype": "str"}, }) ctx.registrar.python.connect("AspectLayout", ctx.display_numpy) ctx.array.connect(ctx.display_numpy.array) ctx.title.connect(ctx.display_numpy.title) ctx.display_numpy.code_update.set("update()") ctx.display_numpy.code_stop.set("destroy()") ctx.code = pythoncell() ctx.code.connect(ctx.display_numpy.code_start) ctx.code.fromfile("cell-display-numpy.py") first = False
def m(ctx, identifier): from seamless import cell, reactor ctx.identifier = cell("str").set(identifier) ctx.rc = reactor({ "text": {"pin": "input", "dtype": "str"}, "identifier": {"pin": "input", "dtype": "str"}, }) ctx.identifier.connect(ctx.rc.identifier) ctx.rc.code_start.cell().set("") ctx.rc.code_update.cell().set("print('M,', PINS.identifier.value, ',' , PINS.text.value)") ctx.rc.code_stop.cell().set("") ctx.export(ctx.rc)
def histo(ctx, title): from seamless import export, cell from seamless.core.worker import ExportedInputPin, ExportedOutputPin from seamless.lib.plotly import plotly from seamless.lib import browse ctx.plotly = plotly(mode="nx") ctx.layout0 = cell("cson") ctx.layout0.connect(ctx.plotly.layout) ctx.attrib0 = cell("cson") ctx.attrib0.connect(ctx.plotly.attrib) ctx.attrib0.set("""[{ type: 'histogram', histnorm: 'probability' marker: { color: 'rgba(100,250,100,0.7)', } }]""") ctx.layout0.set({}) ctx.data = ExportedInputPin(ctx.plotly.data) ctx.attrib = ExportedInputPin(ctx.attrib0) ctx.layout = ExportedInputPin(ctx.layout0) ctx.html = ExportedOutputPin(ctx.plotly.html) browse(ctx.html.cell(), title)
def operator(ctx, formula): from seamless import cell, transformer tparams = ctx.tparams = cell("object").set({ "value": { "pin": "input", "dtype": "int" }, "output": { "pin": "output", "dtype": "int" } }) cont = ctx.cont = transformer(tparams) c_code = cont.code.cell() c_code.set(formula) ctx.export(cont)
def operator(ctx, formula ): from seamless import cell, transformer tparams = ctx.tparams = cell("object").set( { "value": { "pin": "input", "dtype": "int" }, "output": { "pin": "output", "dtype": "int" } } ) cont = ctx.cont = transformer(tparams) c_code = cont.code.cell() c_code.set(formula) ctx.export(cont)
from seamless.lib import edit, display, link ctx = seamless.fromfile("test-sphere3.seamless") #KLUDGE; although file dominant, differences do not trigger a macro update... need to make a new test-sphere.seamless del ctx.subdivisions del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale)
#!/usr/bin/env ipython """Basic example Sets up a transformer that computes a result based on two inputs The input and the transformation code is edited live in a GUI """ from seamless import context, cell, pythoncell, transformer from seamless.lib import edit, display ctx = context() # Create 3 int cells: a=2, b=3, and result ctx.a = cell("int").set(2) ctx.b = cell("int").set(3) ctx.result = cell("int") # Set up a transformer that computes "result" as a function of "a" and "b" t = ctx.transform = transformer({ "a": { "pin": "input", "dtype": "int" }, "b": { "pin": "input", "dtype": "int" }, "result": { "pin": "output", "dtype": "int" }
import seamless from seamless import context, cell, transformer from seamless.lib.filelink import link ctx = context() ctx.value = cell("int") ctx.result = cell("int") #ctx.result.resource.save_policy = 4 #always save value ctx.result.resource.save_policy = 2 #always save hash ctx.tf = transformer({ "value": { "pin": "input", "dtype": "int" }, "result": { "pin": "output", "dtype": "int" }, }) ctx.tf.code.cell().set("""print("evaluate!"); return value""") ctx.value.connect(ctx.tf.value) ctx.tf.result.connect(ctx.result) ctx.value.set(42) ctx.link_value = link(ctx.value, ".", "hashcache-value.txt") ctx.link_result = link(ctx.result, ".", "hashcache-result.txt", file_dominant=True) ctx.equilibrate() ctx.tofile("test-hashcache.seamless",backup=False) ctx = seamless.fromfile("test-hashcache.seamless") ctx.equilibrate() print(ctx.result.value) print("LOAD 1") ctx.destroy()
from seamless.lib import edit, display, link ctx = seamless.fromfile("test-sphere.seamless") del ctx.subdivisions del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals) ctx.load_ply.edges.connect(ctx.edges) ctx.load_ply.triangle_indices.connect(ctx.triangle_indices) ctx.load_ply.triangle_coordinates.connect(ctx.triangle_coordinates_prescale) ctx.load_ply.triangle_normals.connect(ctx.triangle_normals) ctx.filename = cell("str")
@intern resatoms grep $atom !pdb | head -$nhead > headatoms grep $res !headatoms > resatoms $ATTRACTTOOLS/splitmodel !pdb "model" >NULL !> pdbsplit @export pdbsplit @export headatoms @export resatoms """ from seamless import context, cell from seamless.slash import slash0 from seamless.lib.filelink import link from seamless.lib.gui.basic_editor import edit ctx = context() ctx.code = cell(("text", "code", "slash-0")).set(code) ctx.headatoms = cell("text") ctx.resatoms = cell("text") ctx.link_headatoms = link(ctx.headatoms, ".", "headatoms.pdb") ctx.link_resatoms = link(ctx.resatoms, ".", "resatoms.pdb") ctx.link_code = link(ctx.code, ".", "code.slash") ctx.slash0 = slash0(ctx.code) ctx.pdb = cell("text").fromfile("1AVXA.pdb") ctx.pdb.connect(ctx.slash0.pdb) ctx.pdbsplit = cell("json") ctx.slash0.pdbsplit.connect(ctx.pdbsplit) ctx.slash0.headatoms.connect(ctx.headatoms) ctx.slash0.resatoms.connect(ctx.resatoms)
from seamless import context, cell, transformer, reactor from seamless.lib import edit, display, link ctx = seamless.fromfile("test-sphere6.seamless") #KLUDGE; although file dominant, differences do not trigger a macro update... need to make a new test-sphere.seamless del ctx.subdivisions del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals)
def ngl(ctx, molnames): """ Sets up dynamic HTML code to view molecules using the NGL viewer Generates a context with the following pins: Inputs: data_X (where X is each molname): A text pin for the molecule data. As of seamless 0.1, only text is supported transformation_X: A JSON cell for the molecule rotation+translation matrix. Must be a 4x4 matrix in JSON format (list of lists) Default: identity matrix representations: A JSON pin containing the molecular representations The representations are a list of dicts, with each dict containing the following keys: repr: the representation, as understood by NGL. Examples: "cartoon", "spacefill", "ball+stick", "licorice" See http://arose.github.io/ngl/api/manual/usage/molecular-representations.html obj: Optional. A molname of list of molnames to which the representation applies. Default: all molnames All other keys are passed directly to NGL.Stage.addRepresentation() Examples of keys: color, colorScheme: Examples: color: "red", colorScheme: "bfactor" / "element" See: http://arose.github.io/ngl/api/manual/usage/coloring.html sele: Examples: "73-77", ":A", "LYS" See: http://arose.github.io/ngl/api/manual/usage/selection-language.html Output: html: output pin containing the generated dynamic HTML, to be visualized As of seamless 0.1, requires that a copy or link to ngl.js is present in the current directory Macro arguments: molnames: is either a list of molecule names in PDB format, or a dict of (moleculename, dataformat) items, where dataformat is any format understood by NGL.Stage.loadFile() See: http://arose.github.io/ngl/api/manual/usage/file-formats.html http://arose.github.io/ngl/api/Stage.html """ from seamless import cell, transformer, reactor from seamless.lib.dynamic_html import dynamic_html from seamless.lib.templateer import templateer from seamless.core.worker import ExportedInputPin, ExportedOutputPin ctx.tmpl = cell("text").fromfile("ngl-html.jinja") if isinstance(molnames, list): molnames = {name:"pdb" for name in molnames} params = { "update_": { "type": "eval" } } for molname, dataformat in molnames.items(): newparams = { "data_" + molname: { "type": "var", "var": "update.data_" + molname, "dtype": "text", "evals": ["update_"] }, "dataformat_" + molname: { "type": "var", "var": "update.dataformat_" + molname, "dtype": "text", "evals": ["update_"] }, "representations_" + molname: { "type": "var", "var": "update.representations_" + molname, "dtype": "json", "evals": ["update_"] }, "transformation_" + molname: { "type": "var", "var": "update.transformation_" + molname, "dtype": "json", "evals": ["update_"] }, } params.update(newparams) ctx.dynamic = dynamic_html(params) ctx.templateer = templateer({"templates": ["tmpl"], "environment": {"dynamic": ("text", "html")}}) ctx.tmpl.connect(ctx.templateer.tmpl) ctx.dynamic.dynamic_html.cell().connect(ctx.templateer.dynamic) ctx.update_ = cell("text") ctx.update_.set("do_update()"); ctx.update_.connect(ctx.dynamic.update_) transformer_params = { "molnames": {"pin": "input", "dtype": "json"}, "representations": {"pin": "input", "dtype": "json"} } for molname, dataformat in molnames.items(): pinname = "dataformat_" + molname pin = getattr(ctx.dynamic, pinname) pin.cell().set(dataformat) pinname = "transformation_" + molname c = cell("json").set([[1,0,0,0],[0,1,0,0], [0,0,1,0], [0,0,0,1]]) setattr(ctx, "cell_transformation_" + molname, c) c.connect(getattr(ctx.dynamic, pinname)) setattr(ctx, "transformation_" + molname, ExportedInputPin(c)) pinname = "representations_" + molname transformer_params[pinname] = {"pin": "output", "dtype": "json"} # As of seamless 0.1, this has to be a reactor due to multiple outputs t = ctx.transform_representations = reactor(transformer_params) t.molnames.set(list(molnames.keys())) t.code_start.cell().set("") t.code_update.cell().fromfile("cell-transform-representations.py") t.code_stop.cell().set("") for molname, dataformat in molnames.items(): pinname = "representations_" + molname source = getattr(t, pinname).cell() target = getattr(ctx.dynamic, pinname) source.connect(target) ctx.representations = ExportedInputPin(t.representations) ctx.export(ctx.dynamic) ctx.html = ExportedOutputPin(ctx.templateer.RESULT)
from seamless import context, cell, transformer, reactor from seamless.lib import edit, display, link ctx = seamless.fromfile("test-sphere3.seamless") #KLUDGE; although file dominant, differences do not trigger a macro update... need to make a new test-sphere.seamless del ctx.subdivisions del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals)
"pin": "output", "dtype": "int" } }) cont = ctx.cont = transformer(tparams) c_code = cont.code.cell() c_code.set(formula) ctx.export(cont) eparams = ctx.eparams = cell("object").set({ "value": { "pin": "edit", "dtype": "int" }, "title": { "pin": "input", "dtype": "str" }, }) teparams = { "value": { "pin": "edit", "dtype": "str" }, "title": { "pin": "input", "dtype": "str" }, }
def ngl(ctx, molnames, remote_ngl): """ Sets up dynamic HTML code to view molecules using the NGL viewer Generates a context with the following pins: Inputs: data_X (where X is each molname): A text pin for the molecule data. As of seamless 0.1, only text is supported transformation_X: A JSON cell for the molecule rotation+translation matrix. Must be a 4x4 matrix in JSON format (list of lists) Default: identity matrix representations: A JSON pin containing the molecular representations The representations are a list of dicts, with each dict containing the following keys: repr: the representation, as understood by NGL. Examples: "cartoon", "spacefill", "ball+stick", "licorice" See http://arose.github.io/ngl/api/manual/usage/molecular-representations.html obj: Optional. A molname of list of molnames to which the representation applies. Default: all molnames All other keys are passed directly to NGL.Stage.addRepresentation() Examples of keys: color, colorScheme: Examples: color: "red", colorScheme: "bfactor" / "element" See: http://arose.github.io/ngl/api/manual/usage/coloring.html sele: Examples: "73-77", ":A", "LYS" See: http://arose.github.io/ngl/api/manual/usage/selection-language.html Output: html: output pin containing the generated dynamic HTML, to be visualized As of seamless 0.1, requires that a copy or link to ngl.js is present in the current directory TODO: remote_ngl Macro arguments: molnames: is either a list of molecule names in PDB format, or a dict of (moleculename, dataformat) items, where dataformat is any format understood by NGL.Stage.loadFile() See: http://arose.github.io/ngl/api/manual/usage/file-formats.html http://arose.github.io/ngl/api/Stage.html """ from seamless import cell, transformer, reactor from seamless.lib.dynamic_html import dynamic_html from seamless.lib.templateer import templateer from seamless.core.worker import ExportedInputPin, ExportedOutputPin ctx.tmpl = cell("text").fromfile("ngl-html.jinja") if isinstance(molnames, list): molnames = {name: "pdb" for name in molnames} params = {"update_": {"type": "eval"}} for molname, dataformat in molnames.items(): newparams = { "data_" + molname: { "type": "var", "var": "update.data_" + molname, "dtype": "text", "evals": ["update_"] }, "dataformat_" + molname: { "type": "var", "var": "update.dataformat_" + molname, "dtype": "text", "evals": ["update_"] }, "representations_" + molname: { "type": "var", "var": "update.representations_" + molname, "dtype": "json", "evals": ["update_"] }, "transformation_" + molname: { "type": "var", "var": "update.transformation_" + molname, "dtype": "json", "evals": ["update_"] }, } params.update(newparams) ctx.dynamic = dynamic_html(params) ctx.templateer = templateer({ "templates": ["tmpl"], "environment": { "dynamic": ("text", "html"), "ngl_dir": "text" } }) ngl_dir = "https://cdn.rawgit.com/arose/ngl/v0.10.3/dist/" if remote_ngl else "" ctx.templateer.ngl_dir.cell().set(ngl_dir) ctx.tmpl.connect(ctx.templateer.tmpl) ctx.dynamic.dynamic_html.cell().connect(ctx.templateer.dynamic) ctx.update_ = cell("text") ctx.update_.set("do_update()") ctx.update_.connect(ctx.dynamic.update_) transformer_params = { "molnames": { "pin": "input", "dtype": "json" }, "representations": { "pin": "input", "dtype": "json" } } for molname, dataformat in molnames.items(): pinname = "dataformat_" + molname pin = getattr(ctx.dynamic, pinname) pin.cell().set(dataformat) pinname = "transformation_" + molname c = cell("json").set([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) setattr(ctx, "cell_transformation_" + molname, c) c.connect(getattr(ctx.dynamic, pinname)) setattr(ctx, "transformation_" + molname, ExportedInputPin(c)) pinname = "representations_" + molname transformer_params[pinname] = {"pin": "output", "dtype": "json"} # As of seamless 0.1, this has to be a reactor due to multiple outputs t = ctx.transform_representations = reactor(transformer_params) t.molnames.set(list(molnames.keys())) t.code_start.cell().set("") t.code_update.cell().fromfile("cell-transform-representations.py") t.code_stop.cell().set("") for molname, dataformat in molnames.items(): pinname = "representations_" + molname source = getattr(t, pinname).cell() target = getattr(ctx.dynamic, pinname) source.connect(target) ctx.representations = ExportedInputPin(t.representations) ctx.export(ctx.dynamic) ctx.html = ExportedOutputPin(ctx.templateer.RESULT)
pattern = "inp" params = { "outp": {"pin": "output", "dtype": "int"} } code = "return " for n in range(inputs): p = pattern + str(n+1) params[p] = {"pin": "input", "dtype": "int"} code += p + "+ " code = code[:-2] t = transformer(params) t.code.cell().set(code) return t ctx = context() ctx.c1 = cell("int").set(1) ctx.c2 = cell("int").set(2) ctx.t1 = add_all(ctx.c1) ctx.t2 = add_all(ctx.c2) ctx.t1.inp1.cell().set(10) ctx.t2.inp1.cell().set(20) ctx.t2.inp2.cell().set(30) from seamless.lib.gui.basic_editor import edit ctx.ed1 = edit(ctx.t1.outp.cell()) ctx.ed2 = edit(ctx.t2.outp.cell()) code2 = ctx.t1.macro.macro.code.replace('"inp"', '"INP"') ctx.t1.macro.macro.update_code(code2) print(ctx.t2.INP2) ctx.t1.INP1.cell().set(10)
#!/usr/bin/env ipython """Basic example Sets up a transformer that computes a result based on two inputs The input and the transformation code is edited live in a GUI """ from seamless import context, cell, pythoncell, transformer from seamless.lib import edit, display ctx = context() # Create 3 int cells: a=2, b=3, and result ctx.a = cell("int").set(2) ctx.b = cell("int").set(3) ctx.result = cell("int") # Set up a transformer that computes "result" as a function of "a" and "b" t = ctx.transform = transformer({ "a": {"pin": "input", "dtype": "int"}, "b": {"pin": "input", "dtype": "int"}, "result": {"pin": "output", "dtype": "int"} }) # Connect the cells to the transformer pins ctx.a.connect(t.a) ctx.b.connect(t.b) t.result.connect(ctx.result) # Every transformer has an implicit extra input pin, called "code"
tparams = { "value": { "pin": "input", "dtype": "int" }, "output": { "pin": "output", "dtype": "int" } } if __name__ == "__main__": from seamless import cell, pythoncell, transformer, context ctx = context() ctx.c_data = cell("int").set(4) ctx.c_output = cell("int") ctx.c_code = pythoncell() ctx.cont = transformer(tparams) ctx.c_data.connect(ctx.cont.value) ctx.c_code.connect(ctx.cont.code) ctx.c_code.set("return value*2") print(ctx.c_data.data, "'" + ctx.c_code.data + "'", ctx.c_output.data) ctx.cont.output.connect(ctx.c_output) ctx.equilibrate() print(ctx.c_data.data, "'" + ctx.c_code.data + "'", ctx.c_output.data)
import seamless from seamless import cell, context, transformer, reactor from seamless.lib.gui.basic_editor import edit from seamless.lib.gui.basic_display import display import numpy as np ctx = context() a1 = np.arange(10, 20, 1) a2 = np.arange(100, 120, 2) ctx.array1 = cell("array").set(a1) ctx.array2 = cell("array").set(a2) ctx.tf = transformer({ "a1": { "pin": "input", "dtype": "array" }, "a2": { "pin": "input", "dtype": "array" }, "a3": { "pin": "output", "dtype": "array" } }) ctx.array1.connect(ctx.tf.a1) ctx.array2.connect(ctx.tf.a2) ctx.tf.code.cell().set( "print('RUN');import numpy as np; return np.concatenate((a1,a2))") ctx.equilibrate() print(ctx.tf.a3.cell().value)
ctx = context() # Shaders vertex_code = """ void main() { gl_Position = vec4(1.0, 1.0, 1.0, 1.0); } """ fragment_code = """ void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);; } """ ctx.vertex_shader = cell(("text", "code", "vertexshader")).set(vertex_code) ctx.fragment_shader = cell(("text", "code", "fragmentshader")).set(fragment_code) # Program program = { "arrays": [], "uniforms": {}, "render": { "command": "points", "glstate": {}, "attributes": {}, }, } ctx.pre_program = cell("json").set(program) ctx.gen_program = transformer({"program": {"pin": "input", "dtype": "json"},
""" data = np.zeros(4, [("position", np.float32, 2), ("color", np.float32, 4)]) """ data = np.zeros(4, [("position", [('x', np.float32), ('y', np.float32)]), ("color", [('r', np.float32), ('g', np.float32), ('b', np.float32), ('a', np.float32)]) ]) data['color'] = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1), (1, 1, 0, 1)] data['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)] indices = np.array((1,2,3,0,1,2),dtype=np.uint16) c = ctx.array_default = cell("array") c.set_store("GL") c.set(data) c = ctx.array_indices = cell("array") c.set_store("GL") c.set(indices) # Shaders vertex_code = """ uniform float scale; attribute vec4 color; attribute vec2 position; varying vec4 v_color; void main() {
from seamless.lib import edit, display, link ctx = seamless.fromfile("test-sphere6.seamless") #KLUDGE; although file dominant, differences do not trigger a macro update... need to make a new test-sphere.seamless del ctx.subdivisions del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale)
import seamless from seamless import context, cell, reactor, transformer from seamless.lib.filelink import link ctx = context() ctx.server = reactor({"socket": {"pin": "output", "dtype": "int"}}) ctx.servercode = ctx.server.code_start.cell() link(ctx.servercode, ".", "test-websockets-lib_pycell.py") ctx.server.code_update.cell().set("") ctx.server.code_stop.cell().set("""server.close()""") from seamless.lib.gui.browser import browse ctx.client_template = cell("text") link(ctx.client_template, ".", "test-websockets_client.jinja") tf_params = {"inp":{"pin": "input", "dtype": "text"}, "identifier":{"pin": "input", "dtype": "text"}, "socket":{"pin": "input", "dtype": "int"}, "outp":{"pin": "output", "dtype": ("text", "html")} } tf_code = """ import jinja2 d = dict(IDENTIFIER=identifier, socket=socket) return jinja2.Template(inp).render(d) """ ctx.client1 = cell(("text", "html")) ctx.tf_client1 = transformer(tf_params) ctx.server.socket.cell().connect(ctx.tf_client1.socket) ctx.client_template.connect(ctx.tf_client1.inp)
Integer a = 1 Float b = 2.0 Bool c = True String x = "OK" } """ silk_model2 = """ Type SilkModel { Integer a = 1 Float b = 2.0 Bool c = True String x = "OK2" } """ ctx.silk_model = cell(("text", "code", "silk")) ctx.silk_model.set(silk_model) ctx.registrar.silk.register(ctx.silk_model) ctx.n = cell("int").set(3) ctx.mode = cell("str").set("standard") ctx.value = cell("text") ctx.cons = construct_silk_model(ctx.mode) ctx.cons.value.connect(ctx.value) ctx._validate_path() ctx.silk_model.set(silk_model2) #time.sleep(0.001) ctx.equilibrate() print(ctx.value.data)
from seamless.slash import slash0 import time code = """ @input_doc pulse_py @input_var pulses @input_var delay @intern count @intern value python3 !pulse_py $pulses $delay > count tail -1 !count > value @export value """ ctx = context() ctx.pre_code = cell(("text", "code", "slash-0")).set(code) gen_code = ctx.gen_code = transformer({ "in_code": { "pin": "input", "dtype": ("text", "code", "slash-0") }, "monitor": { "pin": "input", "dtype": "bool" }, "out_code": { "pin": "output", "dtype": ("text", "code", "slash-0") }, }) gen_code.monitor.set(False)
from seamless import context, cell, transformer, reactor from seamless.lib import edit, display, link ctx = seamless.fromfile("test-sphere2.seamless") #KLUDGE; although file dominant, differences do not trigger a macro update... need to make a new test-sphere.seamless del ctx.subdivisions del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals)
def plotly(ctx, *, dynamic_html, mode): from seamless import context, cell, transformer from seamless.lib.templateer import templateer from seamless.core.worker import \ ExportedInputPin, ExportedOutputPin assert mode in ("nx", "nxy", "manual"), mode data_dtype = "json" if mode == "manual" else "text" #csv # Subcontexts ctx.values = context() ctx.templates = context() ctx.params = context() ctx.code = context() # Static HTML output ctx.values.html = cell(("text", "html")) ctx.html = ExportedOutputPin(ctx.values.html) # Templates ctx.templates.html_head_body = cell(("text", "html"))\ .fromfile("template-html-head-body.jinja") ctx.templates.head = cell("text")\ .fromfile("template-head.jinja") ctx.templates.body = cell("text")\ .fromfile("template-body.jinja") ctx.templates.body_dynamic = cell("text")\ .fromfile("template-body-dynamic.jinja") # Values: here is where all authoritative state goes ctx.values.title = cell("str").set("Seamless Plotly") ctx.values.data = cell(data_dtype) ctx.values.attrib = cell("json") ctx.values.layout = cell("json") ctx.values.config = cell("json").set({}) ctx.values.width = cell("int").set(500) ctx.values.height = cell("int").set(500) ctx.values.divname = cell("str").set("plotlydiv") # Input pins ctx.title = ExportedInputPin(ctx.values.title) ctx.data = ExportedInputPin(ctx.values.data) ctx.attrib = ExportedInputPin(ctx.values.attrib) ctx.layout = ExportedInputPin(ctx.values.layout) ctx.config = ExportedInputPin(ctx.values.config) # Static HTML: templateer_static params_static = {"environment": {"title": "str", "divname": "str", "width": "int", "height": "int", "plotly_data": "json", "layout": "json", "config": "json", }, "templates": ["body", "head", "head_body"], "result": "head_body"} ctx.params.templateer_static = cell("json").set(params_static) ctx.templateer_static = templateer(ctx.params.templateer_static) ctx.values.height.connect(ctx.templateer_static.height) ctx.values.width.connect(ctx.templateer_static.width) ctx.values.divname.connect(ctx.templateer_static.divname) ctx.values.config.connect(ctx.templateer_static.config) ctx.values.layout.connect(ctx.templateer_static.layout) ctx.values.title.connect(ctx.templateer_static.title) ctx.templates.body.connect(ctx.templateer_static.body) ctx.templates.head.connect(ctx.templateer_static.head) ctx.templates.html_head_body.connect(ctx.templateer_static.head_body) ctx.templateer_static.RESULT.connect(ctx.values.html) #plotly_data temporary ctx.temp_plotly_data = cell("json") ctx.temp_plotly_data.connect(ctx.templateer_static.plotly_data) # Data integrator ctx.integrate_data = transformer({ "data": {"pin": "input", "dtype": "json"}, "attrib": {"pin": "input", "dtype": "json"}, "plotly_data": {"pin": "output", "dtype": "json"}, }) ctx.code.integrate_data = cell(("text", "code","python"))\ .fromfile("cell-integrate-data.py") ctx.code.integrate_data.connect(ctx.integrate_data.code) ctx.values.attrib.connect(ctx.integrate_data.attrib) ctx.integrate_data.plotly_data.connect(ctx.temp_plotly_data) if mode != "manual": #loaded_data temporary ctx.temp_loaded_data = cell("json") ctx.temp_loaded_data.connect(ctx.integrate_data.data) # Pandas data loader ctx.load_data = transformer({ "csv": {"pin": "input", "dtype": "text"}, "data": {"pin": "output", "dtype": "json"}, }) c = ctx.code.load_data = cell(("text", "code","python")) if mode == "nxy": c.fromfile("cell-load-data-nxy.py") elif mode == "nx": c.fromfile("cell-load-data-nx.py") ctx.code.load_data.connect(ctx.load_data.code) ctx.values.data.connect(ctx.load_data.csv) ctx.load_data.data.connect(ctx.temp_loaded_data) else: ctx.values.data.connect(ctx.integrate_data.data) if not dynamic_html: return from seamless.lib.dynamic_html import dynamic_html # Dynamic HTML output ctx.values.dynamic_html = cell(("text", "html")) ctx.dynamic_html = ExportedOutputPin(ctx.values.dynamic_html) # Dynamic HTML: templateer_dynamic ctx.params.templateer_dynamic = cell("json") params = {"environment": {"title": "text", "divname": "text", "width": "int", "height": "int", "dynamic_html": ("text","html") }, "templates": ["body", "head", "head_body"], "result": "head_body"} ctx.params.templateer_dynamic.set(params) ctx.templateer_dynamic = templateer(ctx.params.templateer_dynamic) ctx.values.height.connect(ctx.templateer_dynamic.height) ctx.values.width.connect(ctx.templateer_dynamic.width) ctx.values.divname.connect(ctx.templateer_dynamic.divname) ctx.values.title.connect(ctx.templateer_dynamic.title) ctx.templates.body_dynamic.connect(ctx.templateer_dynamic.body) ctx.templates.head.connect(ctx.templateer_dynamic.head) ctx.templates.html_head_body.connect(ctx.templateer_dynamic.head_body) ctx.templateer_dynamic.RESULT.connect(ctx.values.dynamic_html) # Dynamic HTML maker # TODO: more efficient plot regeneration ctx.params.dynamic_html_maker = cell("json") dynamic_html_params = { "divname": {"type": "var", "dtype": "str"}, "plotly_data": {"type": "var", "dtype": "json", "evals":["make_plot"]}, #"data": {"type": "var", "dtype": "json", "evals":["update_data"]}, #"attrib": {"type": "var", "dtype": "json", "evals":["update_attrib"]}, #"layout": {"type": "var", "dtype": "json", "evals":["update_layout"]}, "data": {"type": "var", "dtype": "json"}, "attrib": {"type": "var", "dtype": "json", "evals":["make_plot"]}, "layout": {"type": "var", "dtype": "json", "evals":["make_plot"]}, "config": {"type": "var", "dtype": "json", "evals":["make_plot"]}, "update_data": {"type": "eval", "on_start": False}, "update_attrib": {"type": "eval", "on_start": False}, "update_layout": {"type": "eval", "on_start": False}, "make_plot": {"type": "eval", "on_start": True}, } ctx.params.dynamic_html_maker.set(dynamic_html_params) ctx.dynamic_html_maker = dynamic_html(ctx.params.dynamic_html_maker) ctx.dynamic_html_maker.dynamic_html.cell().connect( ctx.templateer_dynamic.dynamic_html ) ctx.temp_plotly_data.connect(ctx.dynamic_html_maker.plotly_data) if mode == "manual": ctx.values.data.connect(ctx.dynamic_html_maker.data) else: ctx.temp_loaded_data.connect(ctx.dynamic_html_maker.data) ctx.values.attrib.connect(ctx.dynamic_html_maker.attrib) ctx.values.config.connect(ctx.dynamic_html_maker.config) ctx.values.layout.connect(ctx.dynamic_html_maker.layout) ctx.dynamic_html_maker.make_plot.cell().set(""" Plotly.newPlot(divname, plotly_data, layout, config); """) ctx.dynamic_html_maker.update_data.cell().set(""" var i, ii, subdata, update, attribname; for (i = 0; i < plotly_data.length; i++) { subdata = data[i]; update = {}; for (var attribname in subdata) { update[attribname] = [subdata[attribname]]; } /*if (i==0) { x = document.getElementById("echo"); x.innerHTML = "<pre>" + JSON.stringify(update) + "</pre>"; }*/ Plotly.restyle(divname, update, [i]); } """) ctx.dynamic_html_maker.update_attrib.cell().set(""" var i; for (i = 0; i < plotly_data.length; i++) { Plotly.restyle(divname, attrib[i], [i]); } """) ctx.dynamic_html_maker.update_layout.cell().set(""" Plotly.relayout(divname, layout); """) ctx.values.divname.connect(ctx.dynamic_html_maker.divname)
from seamless import context, cell, transformer, reactor from seamless.lib import edit, display, link from seamless.lib.gui.gl import glprogram, glwindow import numpy as np ctx = context() ctx.params = context() ctx.links = context() ctx.code = context() #for now, gen_sphere must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.gen_sphere = cell(("cson", "seamless", "reactor_params")) ctx.links.params_gen_sphere = link(c, ".", "params-gen-sphere.cson") rc = ctx.gen_sphere = reactor(c) c = ctx.code.gen_sphere = cell(("text", "code", "python")) ctx.links.code_gen_sphere = link(c, ".", "cell-gen-sphere.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.subdivisions = cell("int").set(3) ctx.minimizations = cell("int").set(20) ctx.coordinates = cell("array").set_store("GL") ctx.normals = cell("array").set_store("GL") ctx.edges = cell("array").set_store("GL") ctx.triangle_indices = cell("array").set_store("GL") ctx.triangle_normals = cell("array").set_store("GL") ctx.triangle_coordinates = cell("array").set_store("GL")
from seamless import context, cell from seamless.lib.filehash import filehash from seamless.lib.gui.basic_display import display import tempfile, os ctx = context() tmpdir = tempfile.gettempdir() msg = "Edit {0}: directory {1}, file {2}" ctx.text = cell("text").set("Lorem ipsum") file_text = "text.txt" title_text = "Text" ctx.fh_text = filehash(tmpdir + os.sep + file_text) ctx.d_text = display(ctx.fh_text.filehash.cell(), "Hash") print(msg.format(title_text, tmpdir, file_text)) import os ctx.tofile(os.path.splitext(__file__)[0] + ".seamless", backup=False)
from seamless import cell, pythoncell, context, reactor, transformer from seamless.silk import Silk import seamless.lib from seamless.lib.gui.basic_editor import edit from seamless.lib.gui.basic_display import display from seamless.lib import link from seamless.lib.gui.gl import glprogram ctx = context() file_dominant = False # Vertexdata Silk model ctx.silk_vertexdata = cell(("text", "code", "silk")) ctx.link_silk_vertexdata = link( ctx.silk_vertexdata, ".", "vertexdata.silk", file_dominant=file_dominant ) ctx.registrar.silk.register(ctx.silk_vertexdata) # Shaders ctx.vert_shader = cell(("text", "code", "vertexshader")) ctx.frag_shader = cell(("text", "code", "fragmentshader")) ctx.link_vert_shader = link(ctx.vert_shader, ".", "vert_shader.glsl", file_dominant=file_dominant) ctx.link_frag_shader = link(ctx.frag_shader, ".", "frag_shader.glsl", file_dominant=file_dominant) # Program template ctx.program_template = cell("cson") ctx.link_program_template = link(ctx.program_template,
import seamless from seamless import context, cell, transformer from seamless.lib.filelink import link ctx = context() ctx.value = cell("int") ctx.result = cell("int") #ctx.result.resource.save_policy = 4 #always save value ctx.result.resource.save_policy = 2 #always save hash ctx.tf = transformer({ "value": { "pin": "input", "dtype": "int" }, "result": { "pin": "output", "dtype": "int" }, }) ctx.tf.code.cell().set("""print("evaluate!"); return value""") ctx.value.connect(ctx.tf.value) ctx.tf.result.connect(ctx.result) ctx.value.set(42) ctx.link_value = link(ctx.value, ".", "hashcache-value.txt") ctx.link_result = link(ctx.result, ".", "hashcache-result.txt", file_dominant=True) ctx.equilibrate() ctx.tofile("test-hashcache.seamless", backup=False) ctx = seamless.fromfile("test-hashcache.seamless") ctx.equilibrate()
from seamless import context, cell, export, transformer from seamless.lib import edit, display, link, browse from seamless.slash import slash0 import sys #Stage 1 # Concatenate PDBs ctx = context() ctx.attract = cell(("text", "code", "slash-0")) # !touch "attract.slash" ctx.attract.fromfile("attract.slash") link(ctx.attract) ctx.attract.set(""" @input_doc pdbA @input_doc pdbB @intern pdb @intern result cat !pdbA !pdbB > pdb cat !pdb > result @export pdb @export result """) ctx.slash = slash0(ctx.attract) export(ctx.slash.pdbA) export(ctx.slash.pdbB) ctx.pdbA.fromfile("unbound/1AVXA.pdb") ctx.pdbB.fromfile("unbound/1AVXB.pdb") export(ctx.slash.pdb)
ctx = context() tmpl = """ <!DOCTYPE html> <html> <head></head> <body> <b>First bird:</b><br> <div id="divbird">No bird</div> <b>Second bird:</b><br> <div id="divbird2">No bird either</div> <br> {{body}} </body> </html> """ ctx.html_tmpl = cell("text").set(tmpl) ctx.templateer = templateer({"templates": ["html_tmpl"], "environment": {"body": ("text", "html")}}) ctx.html_tmpl.connect(ctx.templateer.html_tmpl) ctx.dynamic_html = dynamic_html(params) ctx.dynamic_html.dynamic_html.connect(ctx.templateer.body.cell()) ctx.dynamic_html.html_bird.cell().set("Kakapo") ctx.dynamic_html.var_bird.cell().set("Owl") js = """ var ele = document.getElementById("divbird"); ele.innerHTML = bird; """ ctx.dynamic_html.eval_bird.cell().set(js) browse(ctx.templateer.RESULT.cell()) browse(ctx.templateer.RESULT.cell())
import seamless from seamless import context, cell ctx = context() ctx.value = cell("int") from seamless.lib.gui.combobox import combobox ctx.combobox = combobox("int", [10, 20, 30]) from seamless.lib.filelink import link link(ctx.combobox.code_start.cell()) link(ctx.combobox.code_update.cell()) ctx.combobox.value.connect(ctx.value)
import seamless from seamless import context, cell from seamless.lib import link, browse from seamless.lib.plotly import plotly ctx = context() ctx.plotly = plotly(dynamic_html=True, mode="nxy") ctx.data = cell("text") ctx.link_data = link(ctx.data, ".", "data.csv") ctx.layout = cell("cson") ctx.link_layout = link(ctx.layout, ".", "layout.cson") ctx.attrib = cell("cson") ctx.link_attrib = link(ctx.attrib, ".", "attrib.cson") ctx.data.connect(ctx.plotly.data) ctx.attrib.connect(ctx.plotly.attrib) ctx.layout.connect(ctx.plotly.layout) ctx.html = cell(("text", "html")) ctx.plotly.html.connect(ctx.html) ctx.browser_static = browse(ctx.html, "Static HTML") ctx.dynamic_html = cell(("text", "html")) ctx.plotly.dynamic_html.connect(ctx.dynamic_html) ctx.browser_dynamic = browse(ctx.dynamic_html, "Dynamic HTML")
def glprogram(ctx, program, with_window, window_title): from seamless import cell, reactor, macro from seamless.core.worker import ExportedInputPin, ExportedOutputPin, \ ExportedEditPin from seamless.lib.gui.gl.glwindow import glwindow arrays = program["arrays"] textures = program.get("textures", []) rcparams = { #signals "init": { "pin": "input", "dtype": "signal", }, "paint": { "pin": "input", "dtype": "signal", }, "repaint": { "pin": "output", "dtype": "signal", }, #shaders "vertex_shader": { "pin": "input", "dtype": ("text", "code", "vertexshader"), }, "fragment_shader": { "pin": "input", "dtype": ("text", "code", "fragmentshader"), }, #program "program": { "pin": "input", "dtype": "json", }, #uniforms "uniforms" : { "pin": "input", "dtype": "json" } } for ar in arrays: rcparams["array_" + ar] = {"pin": "input","dtype": "array"} for ar in textures: assert ar not in program["arrays"], ar rcparams["array_" + ar] = {"pin": "input","dtype": "array"} ctx.rcparams = cell("json").set(rcparams) ctx.rc = reactor(ctx.rcparams) ctx.rc.code_start.cell().fromfile("cell-glprogram.py") ctx.rc.code_update.cell().set("do_update()") ctx.rc.code_stop.cell().set("") ctx.rc.program.cell().set(program) if with_window: ctx.glwindow = glwindow(window_title) ctx.glwindow.init.cell().connect(ctx.rc.init) ctx.glwindow.paint.cell().connect(ctx.rc.paint) ctx.rc.repaint.cell().connect(ctx.glwindow.update) ctx.update = ExportedInputPin(ctx.glwindow.update) ctx.painted = ExportedOutputPin(ctx.glwindow.painted) ctx.camera = ExportedEditPin(ctx.glwindow.camera) ctx.last_key = ExportedOutputPin(ctx.glwindow.last_key) ctx.export(ctx.rc)
import seamless from seamless import context, cell from seamless.core.node import ScalarCellNode ctx = context() ctx.a = cell("int").set(10) ctx.b = cell("json") node = ScalarCellNode(ctx.a)
from seamless import cell, context, transformer, time ctx = context() typ = ("json", "seamless", "transformer_params") #typ = "json" c = ctx.c = cell(typ).set({"test":10}) t = ctx.t = transformer({ "input":{"pin": "input", "dtype": typ}, "value":{"pin": "output", "dtype": "int"}, } ) t.code.cell().set("""return input['test']""") c.connect(t.input) x = t.value.cell() ctx.equilibrate() print('X',x.data)
c = export(ctx.plotly.layout, "cson").fromfile("layout.cson") link(c) c = export(ctx.plotly.html) link(c, ".", "plotly.html") browse(c, "Docking clusters") c = export(ctx.plotly.dynamic_html) link(c, ".", "plotly-dynamic.html") browse(c, "Docking clusters (dynamic)") #Stage 2: load real dataset get_ipython().system('./load-real.sh') #Stage 2a: perform (bound) docking, # (re)generating real dataset in cells data2, attrib2 import numpy as np ctx.attract = cell(("text", "code", "slash-0")) from seamless.slash import slash0 ctx.slash = slash0(ctx.attract) ctx.attract.fromfile("attract.slash") link(ctx.attract) export(ctx.slash.energies) export(ctx.slash.ntop, "int").set(100) export(ctx.slash.clust_cutoff, "float").set(10) edit(ctx.ntop, "Top structures") edit(ctx.clust_cutoff, "Clustering cutoff") display(ctx.energies, "Energies") export(ctx.slash.irmsds) display(ctx.irmsds, "i-RMSD") export(ctx.slash.clusters) display(ctx.clusters, "clusters") ctx.colors = cell("text").fromfile("colors.txt")
ctx = context() # Shaders vertex_code = """ void main() { gl_Position = vec4(1.0, 1.0, 1.0, 1.0); } """ fragment_code = """ void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);; } """ ctx.vertex_shader = cell(("text", "code", "vertexshader")).set(vertex_code) ctx.fragment_shader = cell( ("text", "code", "fragmentshader")).set(fragment_code) # Program program = { "arrays": [], "uniforms": {}, "render": { "command": "points", "glstate": {}, "attributes": {}, }, } ctx.pre_program = cell("json").set(program)
import seamless from seamless import context, cell, reactor, transformer from seamless.lib.filelink import link from seamless.lib.gui.browser import browse import time from seamless.websocketserver import websocketserver websocketserver.start() #no-op if the websocketserver has already started assert websocketserver.port == 5678 ctx = context() import jinja2 tmpl = cell("text").fromlibfile(seamless.lib, "dynamic-html.jinja").value vars_ = ["bird"] body = jinja2.Template(tmpl).render({"vars": vars_}) tmpl = """ <!DOCTYPE html> <html> <head></head> <body> <b>First bird:</b><br> <div id="divbird">No bird</div> <b>Second bird:</b><br> <div id="divbird2">No bird either</div> <b>Last message received:<br></b> <div id="echo"></div> <br> {{body}}
tmpl = """ <!DOCTYPE html> <html> <head></head> <body> <b>First bird:</b><br> <div id="divbird">No bird</div> <b>Second bird:</b><br> <div id="divbird2">No bird either</div> <br> {{body}} </body> </html> """ ctx.html_tmpl = cell("text").set(tmpl) ctx.templateer = templateer({ "templates": ["html_tmpl"], "environment": { "body": ("text", "html") } }) ctx.html_tmpl.connect(ctx.templateer.html_tmpl) ctx.dynamic_html = dynamic_html(params) ctx.dynamic_html.dynamic_html.connect(ctx.templateer.body.cell()) ctx.dynamic_html.html_bird.cell().set("Kakapo") ctx.dynamic_html.var_bird.cell().set("Owl") js = """ var ele = document.getElementById("divbird"); ele.innerHTML = bird; """
from seamless.lib import edit, display, link from seamless.lib.gui.gl import glprogram, glwindow import numpy as np from scipy.spatial.distance import cdist ctx = context() ctx.params = context() ctx.links = context() ctx.code = context() file_dominant = True #for now, gen_sphere must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.gen_sphere = cell(("cson", "seamless", "reactor_params")) ctx.links.params_gen_sphere = link(c, ".", "params-gen-sphere.cson", file_dominant=file_dominant) rc = ctx.gen_sphere = reactor(c) c = ctx.code.gen_sphere = cell(("text", "code", "python")) ctx.links.code_gen_sphere = link(c, ".", "cell-gen-sphere.py", file_dominant=file_dominant) rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") do_scale_params = { "input":{"pin": "input", "dtype": "array"}, "scale":{"pin": "input", "dtype": "float"}, "output":{"pin": "output", "dtype": "array"} } ctx.subdivisions = cell("int").set(3) ctx.minimizations = cell("int").set(20)
from seamless.slash import slash0 import time code = """ @input_doc pulse_py @input_var pulses @input_var delay @intern count @intern value python3 !pulse_py $pulses $delay > count tail -1 !count > value @export value """ ctx = context() ctx.pre_code = cell(("text", "code", "slash-0")).set(code) gen_code = ctx.gen_code = transformer({ "in_code": {"pin": "input", "dtype": ("text", "code", "slash-0")}, "monitor": {"pin": "input", "dtype": "bool"}, "out_code": {"pin": "output", "dtype": ("text", "code", "slash-0")}, }) gen_code.monitor.set(False) gen_code.code.set(""" if not monitor: return in_code lines = [] for l in in_code.splitlines(): if l.find("python3 !pulse_py") > -1: l += " @monitor 0.01" lines.append(l) return "\\n".join(lines)
from seamless import context, cell, pythoncell, reactor, transformer from seamless.lib.filelink import link from seamless.lib.gui.basic_display import display from seamless.lib.gui.browser import browse from seamless.lib.gui.basic_editor import edit ctx = context() reg = ctx.registrar.ipython ctx.code = cell(("text", "code", "ipython")) link(ctx.code, ".", "cell-test-ipython-registrar.ipy") reg.register(ctx.code) tf = ctx.get_func_html = transformer({ "outp": { "pin": "output", "dtype": ("text", "html") }, }) tf.code.cell().set("return func_html") reg.connect("func_html", tf) browse(tf.outp.cell()) tf = ctx.run_func = transformer({ "i": { "pin": "input", "dtype": "int" }, "outp": { "pin": "output", "dtype": "float" },