From 15f8ec055cebf01a0d7432d44fb4a8473c51cfc2 Mon Sep 17 00:00:00 2001 From: Ruttor Date: Tue, 12 Sep 2023 20:50:11 +0200 Subject: [PATCH 1/5] add insert function --- package-lock.json | 6 ++++++ zndraw/app.py | 4 ++++ zndraw/static/pycom/Cache.js | 31 +++++++++++++++++++++++++++++++ zndraw/zndraw.py | 4 +++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..bdebce8b0 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "ZnDraw", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/zndraw/app.py b/zndraw/app.py index 6e06daef5..e0cac3979 100644 --- a/zndraw/app.py +++ b/zndraw/app.py @@ -339,3 +339,7 @@ def draw_schema(): @io.on("atoms:delete") def delete_atoms(data): emit("atoms:delete", data, broadcast=True, include_self=False) + +@io.on("atoms:insert") +def insert_atoms(data): + emit("atoms:insert", data, broadcast=True, include_self=False) diff --git a/zndraw/static/pycom/Cache.js b/zndraw/static/pycom/Cache.js index 47f82340e..c5f01096b 100644 --- a/zndraw/static/pycom/Cache.js +++ b/zndraw/static/pycom/Cache.js @@ -110,6 +110,37 @@ class Cache { ).innerHTML = `${slider.value} / ${slider.max}`; }); + this._socket.on("atoms:insert", (data) => { + // move all keys after id one step forward + console.log(data) + const remainingKeys = Object.keys(this._cache); + const id = parseInt(Object.keys(data)[0]); + for (let i = remainingKeys.length-1; i >= id; i--) { + const currentKey = remainingKeys[i]; + const newIndex = i + 1; + this._cache[newIndex] = this._cache[currentKey]; + delete this._cache[currentKey]; + } + // insert new atoms + this._cache[id] = new Atoms({ + positions: data.positions, + cell: data.cell, + numbers: data.numbers, + colors: data.colors, + radii: data.radii, + connectivity: data.connectivity, + calc: data.calc, + }); + // update slider + const slider = document.getElementById("frame-slider"); + console.log(1); + slider.max = Object.keys(this._cache).length - 1; + console.log(2); + document.getElementById( + "info", + ).innerHTML = `${slider.value} / ${slider.max}`; + }); + this._socket.on("atoms:download", (ids) => { // send all atoms at once const data = {}; diff --git a/zndraw/zndraw.py b/zndraw/zndraw.py index 3f584ab4c..2d92942db 100644 --- a/zndraw/zndraw.py +++ b/zndraw/zndraw.py @@ -173,7 +173,9 @@ def display(self, index): def insert(self, index, value): """Insert atoms before index""" - raise NotImplementedError + self.socket.emit("atoms:insert", {index: atoms_to_json(value)}) + if self.display_new: + self.display(index) def append(self, value: ase.Atoms) -> None: """Append atoms to the end of the list""" From ca783f81137ca92098ba5dc92491567174b28517 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:51:06 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- zndraw/app.py | 3 ++- zndraw/static/pycom/Cache.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zndraw/app.py b/zndraw/app.py index e0cac3979..bff7519bc 100644 --- a/zndraw/app.py +++ b/zndraw/app.py @@ -339,7 +339,8 @@ def draw_schema(): @io.on("atoms:delete") def delete_atoms(data): emit("atoms:delete", data, broadcast=True, include_self=False) - + + @io.on("atoms:insert") def insert_atoms(data): emit("atoms:insert", data, broadcast=True, include_self=False) diff --git a/zndraw/static/pycom/Cache.js b/zndraw/static/pycom/Cache.js index c5f01096b..92a4a42ab 100644 --- a/zndraw/static/pycom/Cache.js +++ b/zndraw/static/pycom/Cache.js @@ -112,10 +112,10 @@ class Cache { this._socket.on("atoms:insert", (data) => { // move all keys after id one step forward - console.log(data) + console.log(data); const remainingKeys = Object.keys(this._cache); const id = parseInt(Object.keys(data)[0]); - for (let i = remainingKeys.length-1; i >= id; i--) { + for (let i = remainingKeys.length - 1; i >= id; i--) { const currentKey = remainingKeys[i]; const newIndex = i + 1; this._cache[newIndex] = this._cache[currentKey]; From 43c85d9d950e644e3604dc855cd67dea5d66d104 Mon Sep 17 00:00:00 2001 From: Fabian <46721498+PythonFZ@users.noreply.github.com> Date: Sat, 16 Sep 2023 16:53:35 +0200 Subject: [PATCH 3/5] npm update --- zndraw/static/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zndraw/static/package-lock.json b/zndraw/static/package-lock.json index e12c3e53b..91bc02141 100644 --- a/zndraw/static/package-lock.json +++ b/zndraw/static/package-lock.json @@ -62,9 +62,9 @@ } }, "node_modules/@types/node": { - "version": "20.5.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.9.tgz", - "integrity": "sha512-PcGNd//40kHAS3sTlzKB9C9XL4K0sTup8nbG5lC14kzEteTNuAFh9u5nA0o5TWnSG2r/JNPRXFVcHJIIeRlmqQ==" + "version": "20.6.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz", + "integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==" }, "node_modules/accepts": { "version": "1.3.8", @@ -87,9 +87,9 @@ } }, "node_modules/bootstrap": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.1.tgz", - "integrity": "sha512-jzwza3Yagduci2x0rr9MeFSORjcHpt0lRZukZPZQJT1Dth5qzV7XcgGqYzi39KGAVYR8QEDVoO0ubFKOxzMG+g==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.2.tgz", + "integrity": "sha512-D32nmNWiQHo94BKHLmOrdjlL05q1c8oxbtBphQFb9Z5to6eGRDCm0QgeaZ4zFBHzfg2++rqa2JkqCcxDy0sH0g==", "funding": [ { "type": "github", From 638425e66774fb3c0fcebb908d5836c165ab99df Mon Sep 17 00:00:00 2001 From: Fabian <46721498+PythonFZ@users.noreply.github.com> Date: Sat, 16 Sep 2023 17:01:07 +0200 Subject: [PATCH 4/5] bugfix --- zndraw/static/pycom/Cache.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/zndraw/static/pycom/Cache.js b/zndraw/static/pycom/Cache.js index 393ff1bb4..69f249ba6 100644 --- a/zndraw/static/pycom/Cache.js +++ b/zndraw/static/pycom/Cache.js @@ -123,7 +123,6 @@ class Cache { this._socket.on("atoms:insert", (data) => { // move all keys after id one step forward - console.log(data); const remainingKeys = Object.keys(this._cache); const id = parseInt(Object.keys(data)[0]); for (let i = remainingKeys.length - 1; i >= id; i--) { @@ -134,19 +133,18 @@ class Cache { } // insert new atoms this._cache[id] = new Atoms({ - positions: data.positions, - cell: data.cell, - numbers: data.numbers, - colors: data.colors, - radii: data.radii, - connectivity: data.connectivity, - calc: data.calc, + positions: data[id].positions, + cell: data[id].cell, + numbers: data[id].numbers, + colors: data[id].colors, + radii: data[id].radii, + connectivity: data[id].connectivity, + calc: data[id].calc, + pbc: data[id].pbc, }); // update slider const slider = document.getElementById("frame-slider"); - console.log(1); slider.max = Object.keys(this._cache).length - 1; - console.log(2); document.getElementById( "info", ).innerHTML = `${slider.value} / ${slider.max}`; From b517b2601e4ae6bb1b7b5e004c0cc5dfe84d51dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 16 Sep 2023 15:01:14 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- zndraw/static/pycom/Cache.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zndraw/static/pycom/Cache.js b/zndraw/static/pycom/Cache.js index 69f249ba6..b47288234 100644 --- a/zndraw/static/pycom/Cache.js +++ b/zndraw/static/pycom/Cache.js @@ -134,13 +134,13 @@ class Cache { // insert new atoms this._cache[id] = new Atoms({ positions: data[id].positions, - cell: data[id].cell, - numbers: data[id].numbers, - colors: data[id].colors, - radii: data[id].radii, - connectivity: data[id].connectivity, - calc: data[id].calc, - pbc: data[id].pbc, + cell: data[id].cell, + numbers: data[id].numbers, + colors: data[id].colors, + radii: data[id].radii, + connectivity: data[id].connectivity, + calc: data[id].calc, + pbc: data[id].pbc, }); // update slider const slider = document.getElementById("frame-slider");