diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b3ad03..fc8b12a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,18 @@ jobs: chmod +x .host/code-snippets/*.AppImage (cd .host/code-snippets && ./animathio_2.1.0_x86_64.AppImage --appimage-extract > /dev/null) python3 community/code-snippets/smoke.py .host/code-snippets/squashfs-root/usr/bin/animathio-cli target/plugins + - name: Get released AniMathIO 2.3.0 + id: molecule-host + uses: ./.github/actions/animathio-cli + with: + github-token: ${{ github.token }} + tag: v2.3.0 + asset: animathio_2.3.0_x86_64.AppImage + sha256: ca7d4e613a7ec049bdb9aa8ecf6fc63ddae2ce10c70b2ec26632569a9ebdd148 + - name: Test Molecule Studio on released 2.3.0 + env: + ANIMATHIO_CLI: ${{ steps.molecule-host.outputs.cli }} + run: python3 community/molecule/smoke.py "$ANIMATHIO_CLI" target/plugins - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: plugins diff --git a/README.md b/README.md index b477559..a5a15b3 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ MIT licensed, like AniMathIO. Plugins are sandboxed WebAssembly components. | Name | Author | Description | License | ABI | Source | | --- | --- | --- | --- | --- | --- | | [Code Snippets](https://github.com/AniMathIO/plugins/tree/HEAD/community/code-snippets) | AniMathIO | Syntax-highlighted code with type-on reveal and token morph animations | MIT AND OFL-1.1 | 1.1.0 | [AniMathIO/plugins](https://github.com/AniMathIO/plugins/tree/HEAD/community/code-snippets) | +| [Molecule Studio](https://github.com/AniMathIO/plugins/tree/HEAD/community/molecule) | AniMathIO | Self-drawing 2D molecular structures and reactions from SMILES, with CPK colors and wedge/dash stereo | MIT | 1.1.0 | [AniMathIO/plugins](https://github.com/AniMathIO/plugins/tree/HEAD/community/molecule) | Install from the editor's Plugins tab in AniMathIO 2.2+, or manually as described diff --git a/community-plugins.json b/community-plugins.json index dd7d98f..b2aef28 100644 --- a/community-plugins.json +++ b/community-plugins.json @@ -11,6 +11,16 @@ "path": "community/code-snippets", "license": "MIT AND OFL-1.1", "min_abi": "1.1.0" + }, + { + "id": "io.github.animathio.molecule", + "name": "Molecule Studio", + "author": "AniMathIO", + "description": "Self-drawing 2D molecular structures and reactions from SMILES, with CPK colors and wedge/dash stereo", + "repo": "AniMathIO/plugins", + "path": "community/molecule", + "license": "MIT", + "min_abi": "1.1.0" } ], "delisted": [] diff --git a/community/molecule/Cargo.lock b/community/molecule/Cargo.lock new file mode 100644 index 0000000..7938775 --- /dev/null +++ b/community/molecule/Cargo.lock @@ -0,0 +1,991 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "auditable-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7bf8143dfc3c0258df908843e169b5cc5fcf76c7718bd66135ef4a9cd558c5" +dependencies = [ + "semver", + "serde", + "serde_json", + "topological-sort", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "bumpalo" +version = "3.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "chematic-core" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2349d243db159ae92fca06336c8671dde7c300999339c72012adc500b56fb611" + +[[package]] +name = "chematic-depict" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3566ed1947b0d251cd2aa28ca7426fcf46e8d26877e20479b897c8a21f4a521" +dependencies = [ + "chematic-core", + "chematic-perception", + "chematic-rxn", + "chematic-smiles", + "rustc-hash", + "serde", + "serde_json", +] + +[[package]] +name = "chematic-perception" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb572ad25721a67ec637ab1f9946d0c73f4962f8f308ce4f87db748ed763003d" +dependencies = [ + "chematic-core", + "rustc-hash", + "smallvec", +] + +[[package]] +name = "chematic-rxn" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc8d9081dd78e2632b05de8cf80fd05061ce8322b4ea7aa787fc76b4440d0e8" +dependencies = [ + "chematic-core", + "chematic-perception", + "chematic-smarts", + "chematic-smiles", + "rustc-hash", + "serde", + "serde_json", +] + +[[package]] +name = "chematic-smarts" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73d15da2babdb267139a1ba6575f7127589c523719d2fe155074445c8b91fff6" +dependencies = [ + "chematic-core", + "chematic-perception", + "rustc-hash", + "web-time", +] + +[[package]] +name = "chematic-smiles" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f4432ce984a65c4b25d60f7740e5aa6f3b4c7ca75ff997f479e621c71126aa" +dependencies = [ + "chematic-core", + "chematic-perception", + "smallvec", +] + +[[package]] +name = "crc32fast" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "flate2" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.2", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "molecule" +version = "0.1.0" +dependencies = [ + "chematic-core", + "chematic-depict", + "chematic-perception", + "chematic-smiles", + "wit-bindgen", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.119", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59" + +[[package]] +name = "spdx" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3" +dependencies = [ + "smallvec", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "url" +version = "2.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" +dependencies = [ + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.10", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bb72f02e7fbf07183443b27b0f3d4144abf8c114189f2e088ed95b696a7822" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce1ef0faabbbba6674e97a56bee857ccddf942785a336c8b47b42373c922a91d" +dependencies = [ + "anyhow", + "auditable-serde", + "flate2", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "url", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f51cad774fb3c9461ab9bccc9c62dfb7388397b5deda31bf40e8108ccd678b2" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wit-bindgen" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e7091ed6c9abfa4e0a2ef3b39d0539da992d841fcf32c255f64fb98764ffee5" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "398c650cec1278cfb72e214ba26ef3440ab726e66401bd39c04f465ee3979e6b" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68faed92ae696b93ea9a7b67ba6c37bf09d72c6d9a70fa824a743c3020212f11" +dependencies = [ + "bitflags", + "futures", + "once_cell", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83903c8dcd8084a8a67ae08190122cf0e25dc37bdc239070a00f47e22d3f0aae" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn 2.0.119", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7bf7f20495bcc7dc9f24c5fbcac9e919ca5ebdb7a1b1841d74447d3c8dd0c60" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.119", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "635c3adc595422cbf2341a17fb73a319669cc8d33deed3a48368a841df86b676" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddf445ed5157046e4baf56f9138c124a0824d4d1657e7204d71886ad8ce2fc11" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/community/molecule/Cargo.toml b/community/molecule/Cargo.toml new file mode 100644 index 0000000..3bc682e --- /dev/null +++ b/community/molecule/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "molecule" +version = "0.1.0" +edition = "2021" +license = "MIT" +publish = false + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +wit-bindgen = "=0.40.0" +# Chemistry engine (SMILES parsing, perception, 2D depiction layout, CPK palette). +# MIT OR Apache-2.0; pinned exactly and credited in NOTICE with upstream licenses +# under assets/. +chematic-core = "=1.2.3" +chematic-smiles = { version = "=1.2.3", default-features = false } +chematic-perception = { version = "=1.2.3", default-features = false } +chematic-depict = { version = "=1.2.3", default-features = false } + +[profile.release] +opt-level = 3 +lto = true +strip = "debuginfo" + +[workspace] diff --git a/community/molecule/NOTICE b/community/molecule/NOTICE new file mode 100644 index 0000000..e872f0f --- /dev/null +++ b/community/molecule/NOTICE @@ -0,0 +1,29 @@ +Molecule Studio for AniMathIO +Copyright (c) 2026 AniMathIO contributors. MIT (see ../../LICENSE). + +Compiled chemistry dependency: +chematic 1.2.3, Kentaro Tanabe (kent-tokyo), MIT OR Apache-2.0 +https://github.com/kent-tokyo/chematic/tree/f63733dec7ae8a63262e9ec0c29cd916b2e7954b +Copyright (c) 2026 Kentaro Tanabe (kent-tokyo). +Both upstream licenses are retained in assets/chematic-LICENSE-MIT and +assets/chematic-LICENSE-APACHE. Cargo.lock records the exact packages. +Molecule Studio uses chematic-core, chematic-smiles, chematic-perception and +chematic-depict directly for SMILES parsing, valence and hydrogen counts, +ring perception, 2D coordinates, Kekule bond assignment and CPK colors. +The upstream source is used through these dependencies without modification. + +Animation reference: +manim-Chemistry, UnMolDeQuimica contributors, MIT +https://github.com/UnMolDeQuimica/manim-Chemistry/tree/c03147d4f9374cd75b58257962210e9020895d15 +Copyright (c) 2023 UMDQ. License in assets/manim-Chemistry-LICENSE. +GraphMolecule construction and the staging of reaction examples informed the +write-on design. All animation code and assets in Molecule Studio are original. + +Molecule Studio implements the vector bond and label rendering, fit, highlight +and reveal logic, reaction arrows and spacing, and tetrahedral wedge/dash +assignment from the ligand order recorded by chematic. The tetrahedral rules +follow section 3.8.2 of OpenSMILES (https://opensmiles.org/opensmiles.html). +The explicit water depiction uses the measured H–O–H angle reported by the +NIST CCCBDB (https://cccbdb.nist.gov/expangle2x.asp?all=0&descript=aHOH). +The host supplies the glyph outlines through shape-text. The bundle includes +no fonts. diff --git a/community/molecule/README.md b/community/molecule/README.md new file mode 100644 index 0000000..61095b2 --- /dev/null +++ b/community/molecule/README.md @@ -0,0 +1,110 @@ +# Molecule Studio + +Turn SMILES into animated 2D molecular structures and reaction diagrams in AniMathIO. +Molecule Studio draws bonds and atom labels, highlights selected parts of a structure, +and can reveal a reaction one stage at a time. + +Plugin ID `io.github.animathio.molecule` · ABI 1.1.0 · Tested with AniMathIO 2.3.0 + +## Build and use + +From the plugins repository root, build the bundle with Rust and Python 3.11 or later. + +```sh +rustup target add wasm32-wasip2 +bash community/molecule/build.sh +mkdir -p target/plugins +cp community/molecule/target/molecule.amplugin target/plugins/ +``` + +Start AniMathIO with `ANIMATHIO_PLUGIN_DIR` set to the absolute bundle directory, then add +**Molecule Studio** from the Library. The override replaces bundled plugin discovery, so include +any other bundles the project uses. A light project background suits the default drawing colors. +For a dark background, change **Bond and text color** to a light color and turn off CPK colors +if you want all labels to use that same ink. + +- Choose a preset to load water, benzene, caffeine, aspirin, ethanol, glucose, esterification, + aspirin synthesis, or ethanol combustion. Named presets supply both SMILES and mode. +- For your own structure, select **Custom** and enter a SMILES string such as `CC(=O)O`. +- For your own reaction, select **Reaction** and fill in both SMILES fields, or enter + `CC(O)=O.CCO>>CCOC(C)=O.O` in the first field. Separate species on each side with + dots. Repeat a species to show multiple copies, as the ethanol combustion preset does. +- Keyframe **Progress** from 0 to 1 using the inspector diamonds. Structure mode grows the + bonds and fades in labels. In reaction mode the reactants draw during 0–42%, dim during + 42–56%, and remain at 70% opacity through the finished frame. The arrow draws during + 56–74% and the products during 74–100%. A clip without keyframes shows the finished diagram. + +## Parameters + +| Parameter | Default | Effect | +| --- | --- | --- | +| `preset` | `custom` | Supplies named structure or reaction inputs | +| `smiles` | Caffeine | Structure or reactant SMILES. Accepts `reactants>>products` in Custom mode | +| `product_smiles` | Empty | Product side for a custom reaction | +| `mode` | `structure` | `structure` or `reaction` when using Custom | +| `progress` | 1 | Write-on position, clamped to 0–1 | +| `reveal_by` | `bond` | `bond` follows bond order in the input, `atom` follows atom order, and `together` draws all bonds at once | +| `cpk` | On | Color heteroatom labels using the chematic CPK palette | +| `show_carbons` | `bare` | Hide routine skeletal carbon labels or show them with `labeled` | +| `show_hydrogens` | Off | Show hydrogen counts on carbon labels, including terminal carbons in bare mode. Heteroatom hydrogen counts and explicit hydrogen atoms always draw | +| `show_lone_pairs` | Off | Show dots for supported neutral, nonaromatic heteroatoms | +| `atom_numbers` | Off | Show one-based atom numbers in SMILES order | +| `highlight` | Empty | Mix one-based atoms and zero-based bonds, e.g. `1,4-6,b0,b2-3`. Indices restart in each reaction fragment | +| `bond_order_animation` | `inner-line` | Draw the second stroke inside a ring, or use symmetric strokes with `double-stroke` | +| `stroke_width` | 5 | Bond stroke width, 2–16% of a typical bond length | +| `font_size` | 49 | Atom label size, 30–85% of a typical bond length | +| `arrow_label` | Empty | Short caption above a reaction arrow, up to 128 UTF-8 bytes | +| `accent` | Amber | Reaction arrow and highlights | +| `ink` | Dark slate | Bonds, atom numbers and labels outside the CPK palette | + +Isolated five- and six-membered rings expressed with aromatic SMILES use an inner circle. +Fused aromatic systems use alternating orders when chematic can assign them. Tetrahedral +`@` and `@@` markers can produce a solid or hashed wedge with its narrow end at the center. +The explicit water graph uses the measured 104.5° H–O–H angle. +[NIST experimental bond angles](https://cccbdb.nist.gov/expangle2x.asp?all=0&descript=aHOH) + +## Released-host screenshots + +| Caffeine 0% | 25% | 50% | 75% | 100% | +| --- | --- | --- | --- | --- | +| ![Empty canvas](screenshots/caffeine-000.png) | ![First bonds](screenshots/caffeine-025.png) | ![Partial caffeine drawing](screenshots/caffeine-050.png) | ![Nearly finished caffeine drawing](screenshots/caffeine-075.png) | ![Finished caffeine structure](screenshots/caffeine-100.png) | + +| Water with lone pairs | Numbered benzene with highlights | Glucose with stereobonds | +| --- | --- | --- | +| ![Water with two lone pairs](screenshots/water-lone-pairs.png) | ![Benzene ring with selected atoms and bonds](screenshots/benzene-highlight.png) | ![Glucose ring with solid and hashed wedges](screenshots/glucose.png) | + +| Combustion reactants | Arrow in progress | Finished combustion | +| --- | --- | --- | +| ![Ethanol and oxygen](screenshots/combustion-042.png) | ![The arrow drawing after the reactants dim](screenshots/combustion-065.png) | ![Ethanol combustion with carbon dioxide and water](screenshots/combustion-100.png) | + +[Unannotated water](screenshots/water.png) · [Unannotated benzene](screenshots/benzene.png) · +[Aspirin synthesis](screenshots/aspirin-synthesis.png) + +## Implementation and limits + +The WASM component uses chematic 1.2.3 for SMILES parsing, chemistry perception and 2D +layout. It emits vector paths through ABI 1.1.0 and uses the host's `shape-text` import for labels. +The renderer uses only evaluated parameters and canvas dimensions. Per-call layout and glyph +preparation are deterministic, and the component requires no additional capabilities. +Upstream commits and licenses are recorded in [NOTICE](NOTICE). + +Inputs are capped at 512 UTF-8 bytes per SMILES field, including the separator when using +one-field reaction syntax. A complete clip supports up to 128 atoms and 256 bonds across both +sides, with at most eight fragments per side. Bond orders plus bracket hydrogens must fit the +element's common valence limit where defined. The host's sandbox limits also apply. +Cage structures such as cubane and adamantane can produce crowded or overlapping 2D +layouts. E/Z double-bond stereochemistry is unsupported. The plugin does not balance reactions, +model reaction mechanisms, or infer unspecified stereochemistry. + +## Verification + +```sh +CARGO_BUILD_JOBS=2 CARGO_PROFILE_DEV_DEBUG=0 CARGO_INCREMENTAL=0 \ + nice -n 19 ionice -c3 cargo test --manifest-path community/molecule/Cargo.toml --locked +python3 community/molecule/smoke.py /path/to/animathio-cli target/plugins --screenshots +``` + +The smoke script requires Pillow. It verifies repeat renders and a host-sampled progress keyframe +pixel for pixel, compares reveal modes and palettes, checks preset and custom reactions, and +asserts diagnostics on malformed and oversized inputs. It writes fixtures under the plugin's +`target/smoke`. diff --git a/community/molecule/assets/chematic-LICENSE-APACHE b/community/molecule/assets/chematic-LICENSE-APACHE new file mode 100644 index 0000000..3622351 --- /dev/null +++ b/community/molecule/assets/chematic-LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2026 Kentaro Tanabe (kent-tokyo) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/community/molecule/assets/chematic-LICENSE-MIT b/community/molecule/assets/chematic-LICENSE-MIT new file mode 100644 index 0000000..779fbc2 --- /dev/null +++ b/community/molecule/assets/chematic-LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2026 Kentaro Tanabe (kent-tokyo) + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/community/molecule/assets/manim-Chemistry-LICENSE b/community/molecule/assets/manim-Chemistry-LICENSE new file mode 100644 index 0000000..21cd0e4 --- /dev/null +++ b/community/molecule/assets/manim-Chemistry-LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 UMDQ + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/community/molecule/build.sh b/community/molecule/build.sh new file mode 100755 index 0000000..a81f2ea --- /dev/null +++ b/community/molecule/build.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")" +export CARGO_BUILD_JOBS=2 CARGO_PROFILE_DEV_DEBUG=0 CARGO_INCREMENTAL=0 +export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$PWD/target}" +runner=(cargo) +if [[ "$OSTYPE" == linux* ]]; then runner=(nice -n 19 ionice -c3 cargo); fi +"${runner[@]}" build --target wasm32-wasip2 --release --locked +python3 - <<'PACKAGE' +import os, pathlib, tomllib, zipfile +root = pathlib.Path('.') +name = tomllib.loads((root / 'Cargo.toml').read_text())['package']['name'] +out = root / 'target' / (name + '.amplugin') +out.parent.mkdir(exist_ok=True) +target = pathlib.Path(os.environ['CARGO_TARGET_DIR']) +with zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED) as z: + z.write('plugin.toml', 'plugin.toml') + z.write('NOTICE', 'NOTICE') + z.write('../../LICENSE', 'LICENSE') + for notice in ['chematic-LICENSE-MIT', 'chematic-LICENSE-APACHE', 'manim-Chemistry-LICENSE']: + z.write('assets/' + notice, 'licenses/' + notice) + z.write(target / "wasm32-wasip2/release" / f"{name.replace('-', '_')}.wasm", "plugin.wasm") +print(out) +PACKAGE diff --git a/community/molecule/plugin.toml b/community/molecule/plugin.toml new file mode 100644 index 0000000..983d559 --- /dev/null +++ b/community/molecule/plugin.toml @@ -0,0 +1,7 @@ +api_version = "1.1.0" +id = "io.github.animathio.molecule" +name = "Molecule Studio" +version = "0.1.0" +description = "Self-drawing 2D molecular structures and reactions from SMILES, with CPK colors and wedge/dash stereo" +kinds = ["clip-source"] +capabilities = [] diff --git a/community/molecule/screenshots/aspirin-synthesis.png b/community/molecule/screenshots/aspirin-synthesis.png new file mode 100644 index 0000000..ae69f00 Binary files /dev/null and b/community/molecule/screenshots/aspirin-synthesis.png differ diff --git a/community/molecule/screenshots/benzene-highlight.png b/community/molecule/screenshots/benzene-highlight.png new file mode 100644 index 0000000..dce2a1e Binary files /dev/null and b/community/molecule/screenshots/benzene-highlight.png differ diff --git a/community/molecule/screenshots/benzene.png b/community/molecule/screenshots/benzene.png new file mode 100644 index 0000000..20ca476 Binary files /dev/null and b/community/molecule/screenshots/benzene.png differ diff --git a/community/molecule/screenshots/caffeine-000.png b/community/molecule/screenshots/caffeine-000.png new file mode 100644 index 0000000..a562c3f Binary files /dev/null and b/community/molecule/screenshots/caffeine-000.png differ diff --git a/community/molecule/screenshots/caffeine-025.png b/community/molecule/screenshots/caffeine-025.png new file mode 100644 index 0000000..c6d9341 Binary files /dev/null and b/community/molecule/screenshots/caffeine-025.png differ diff --git a/community/molecule/screenshots/caffeine-050.png b/community/molecule/screenshots/caffeine-050.png new file mode 100644 index 0000000..8737c0c Binary files /dev/null and b/community/molecule/screenshots/caffeine-050.png differ diff --git a/community/molecule/screenshots/caffeine-075.png b/community/molecule/screenshots/caffeine-075.png new file mode 100644 index 0000000..12a9264 Binary files /dev/null and b/community/molecule/screenshots/caffeine-075.png differ diff --git a/community/molecule/screenshots/caffeine-100.png b/community/molecule/screenshots/caffeine-100.png new file mode 100644 index 0000000..ab6b965 Binary files /dev/null and b/community/molecule/screenshots/caffeine-100.png differ diff --git a/community/molecule/screenshots/combustion-042.png b/community/molecule/screenshots/combustion-042.png new file mode 100644 index 0000000..0d548a7 Binary files /dev/null and b/community/molecule/screenshots/combustion-042.png differ diff --git a/community/molecule/screenshots/combustion-065.png b/community/molecule/screenshots/combustion-065.png new file mode 100644 index 0000000..cb87500 Binary files /dev/null and b/community/molecule/screenshots/combustion-065.png differ diff --git a/community/molecule/screenshots/combustion-100.png b/community/molecule/screenshots/combustion-100.png new file mode 100644 index 0000000..a1da740 Binary files /dev/null and b/community/molecule/screenshots/combustion-100.png differ diff --git a/community/molecule/screenshots/glucose.png b/community/molecule/screenshots/glucose.png new file mode 100644 index 0000000..d17713f Binary files /dev/null and b/community/molecule/screenshots/glucose.png differ diff --git a/community/molecule/screenshots/water-lone-pairs.png b/community/molecule/screenshots/water-lone-pairs.png new file mode 100644 index 0000000..831e22d Binary files /dev/null and b/community/molecule/screenshots/water-lone-pairs.png differ diff --git a/community/molecule/screenshots/water.png b/community/molecule/screenshots/water.png new file mode 100644 index 0000000..bc05dac Binary files /dev/null and b/community/molecule/screenshots/water.png differ diff --git a/community/molecule/smoke.py b/community/molecule/smoke.py new file mode 100644 index 0000000..628c818 --- /dev/null +++ b/community/molecule/smoke.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python3 +"""Render and check Molecule Studio frames with the released AniMathIO CLI.""" + +import argparse +import json +import os +from pathlib import Path +import subprocess +import zipfile + +from PIL import Image, ImageChops + +ROOT = Path(__file__).resolve().parent +WORK = ROOT / "target" / "smoke" +PLUGIN_ID = "io.github.animathio.molecule" +BACKGROUND = (249, 248, 244) +OXYGEN = (255, 13, 13) +NITROGEN = (48, 80, 248) +ACCENT = (255, 158, 40) +CAFFEINE = "CN1C=NC2=C1C(=O)N(C)C(=O)N2C" +SIZE = (1280, 720) +HOST_ERRORS = ("failed", "trap", "placeholder", "not loaded", "panic") + + +def pixels(image, color): + return sum(count for count, rgb in image.getcolors(image.width * image.height) if rgb == color) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("cli", type=lambda path: Path(path).resolve()) + parser.add_argument("plugin_dir", type=lambda path: Path(path).resolve()) + parser.add_argument("--screenshots", action="store_true", help="refresh the README screenshots") + args = parser.parse_args() + WORK.mkdir(parents=True, exist_ok=True) + env = dict( + os.environ, + ANIMATHIO_PLUGIN_DIR=str(args.plugin_dir), + ANIMATHIO_PLUGIN_SETTINGS=str(WORK / "plugin-settings.json"), + ANIMATHIO_USER_PLUGIN_DIR=str(WORK / "user-plugins"), + ANIMATHIO_AUDIO="none", + XDG_CONFIG_HOME=str(WORK / "config"), + XDG_DATA_HOME=str(WORK / "data"), + XDG_CACHE_HOME=str(WORK / "cache"), + TMPDIR=str(WORK), + PIPEWIRE_REMOTE="animathio-silent-no-such-remote", + PULSE_SERVER="unix:/nonexistent/animathio-silent", + SDL_AUDIODRIVER="dummy", + ) + + def run(*command): + return subprocess.run( + [args.cli, *map(str, command)], env=env, capture_output=True, text=True, timeout=30 + ) + + sample = WORK / "sample.amio" + sample.unlink(missing_ok=True) + run("new-sample", "-o", sample).check_returncode() + with zipfile.ZipFile(sample) as bundle: + project = json.loads(bundle.read("project.json")) + project.update(width=SIZE[0], height=SIZE[1], assets={}, background=[*BACKGROUND, 255]) + project["tracks"] = project["tracks"][:1] + clip = project["tracks"][0]["clips"]["1"] + clip.update(animations=[], effects=[]) + background = Image.new("RGB", SIZE, BACKGROUND) + + def render(name, *, frame=0, diagnostic=None, **params): + clip["kind"] = {"Plugin": {"plugin_id": PLUGIN_ID, "params": params}} + path = WORK / f"{name}.amio" + with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as bundle: + bundle.writestr("project.json", json.dumps(project)) + if diagnostic: + # PNG preview substitutes an error placeholder. Export exposes the + # guest diagnostic and fails before encoding an invalid clip. + result = run("export", path, "--to", 0.034, "-o", WORK / f"{name}.webm", "--overwrite") + report = result.stdout + result.stderr + assert result.returncode and diagnostic in report and "trap" not in report.lower(), report + print(f"PASS {name} ({diagnostic})") + return None + png = WORK / f"{name}.png" + png.unlink(missing_ok=True) + result = run("render", path, "--frame", frame, "-o", png) + report = result.stdout + result.stderr + if result.returncode or any(word in result.stderr.lower() for word in HOST_ERRORS): + raise RuntimeError(f"{name}\n{report}") + with Image.open(png) as image: + raster = image.convert("RGB") + extent = ImageChops.difference(raster, background).getbbox() + if extent: + x0, y0, x1, y1 = extent + assert 0 < x0 < x1 < raster.width and 0 < y0 < y1 < raster.height, (name, extent) + ink_or_oxygen = sum( + count for count, (r, g, b) in raster.getcolors(raster.width * raster.height) + if (r < 200 and g < 200 and b < 205) or (r > 225 and max(g, b) < 180) + ) + assert ink_or_oxygen > 30, name + else: + assert params.get("progress") == 0.0, f"{name} unexpectedly blank" + print(f"PASS {name}") + return raster + + frames = {} + for percent in (0, 25, 50, 75, 100): + name = f"caffeine-{percent:03}" + frames[name] = render(name, preset="caffeine", progress=percent / 100) + caffeine = frames["caffeine-100"] + assert caffeine.tobytes() == render("default").tobytes() + assert frames["caffeine-000"].tobytes() == background.tobytes() + assert len({image.tobytes() for image in frames.values()}) == len(frames) + assert pixels(caffeine, OXYGEN) > 50 and pixels(caffeine, NITROGEN) > 50 + assert frames["caffeine-050"].tobytes() == render("repeat", progress=0.5).tobytes() + + for mode in ("atom", "together"): + image = render(f"{mode}-050", progress=0.5, reveal_by=mode) + assert image.tobytes() != frames["caffeine-050"].tobytes() + assert caffeine.tobytes() == render(f"{mode}-100", reveal_by=mode).tobytes() + + clip["animations"] = [{ + "target": {"Param": "progress"}, + "keys": { + "0": {"value": {"Number": 0.0}, "interpolation": "Linear"}, + "705600000": {"value": {"Number": 1.0}, "interpolation": "Hold"}, + }, + }] + assert frames["caffeine-050"].tobytes() == render("keyframed", frame=15, progress=0.0).tobytes() + clip["animations"] = [] + + # Explicit defaults mirror a clip created by the editor before choosing a preset. + stored = dict(smiles=CAFFEINE, product_smiles="", mode="structure") + for preset in ("water", "benzene", "glucose"): + frames[preset] = render(preset, preset=preset, **stored) + assert frames[preset].tobytes() != caffeine.tobytes() + assert pixels(frames["water"], OXYGEN) > 100 + assert pixels(frames["benzene"], OXYGEN) == 0 + annotated = render("highlights", preset="benzene", progress=0, highlight="1,4-6,b0,b2-3") + assert annotated.tobytes() == background.tobytes() + frames["benzene-highlight"] = render( + "benzene-highlight", preset="benzene", highlight="1,4-6,b0,b2-3", atom_numbers=True + ) + assert frames["benzene-highlight"].tobytes() != frames["benzene"].tobytes() + mono = render("monochrome", cpk=False) + assert pixels(mono, OXYGEN) == 0 and pixels(mono, NITROGEN) == 0 + render("alternate-double-bond", preset="aspirin", bond_order_animation="double-stroke") + frames["water-lone-pairs"] = render("water-lone-pairs", preset="water", show_lone_pairs=True) + render("hydrogens", preset="ethanol", show_hydrogens=True, show_carbons="labeled") + render("charged-amine", smiles="C[NH3+]") + render("hydronium", smiles="[OH3+]") + + for percent in (0, 42, 65, 100): + name = f"combustion-{percent:03}" + frames[name] = render( + name, preset="ethanol-combustion", arrow_label="combustion", + progress=percent / 100, **stored, + ) + assert frames["combustion-000"].tobytes() == background.tobytes() + assert pixels(frames["combustion-042"], ACCENT) == 0 + assert pixels(frames["combustion-065"], ACCENT) > 60 + assert pixels(frames["combustion-100"], ACCENT) > pixels(frames["combustion-065"], ACCENT) + assert frames["combustion-100"].tobytes() == render( + "custom-reaction", smiles="CCO.O=O.O=O.O=O>>O=C=O.O=C=O.O.O.O", + arrow_label="combustion", + ).tobytes() + frames["aspirin-synthesis"] = render("aspirin-synthesis", preset="aspirin-synthesis") + render("separate-reaction", mode="reaction", smiles="CC(O)=O.CCO", product_smiles="CCOC(C)=O.O") + + render("bounded-chain", smiles="C" * 128) + render("bounded-fragments", mode="reaction", smiles=".".join(["O"] * 8), + product_smiles=".".join(["O"] * 8)) + render("invalid-smiles", smiles="C1CC", diagnostic="invalid-input") + render("overvalent-carbon", smiles="CC(C)(C)(C)(C)C", diagnostic="invalid-input") + render("overvalent-bracket-hydrogens", smiles="[CH5]", diagnostic="invalid-input") + render("oversized-smiles", smiles="C" * 513, diagnostic="limit-exceeded") + render("oversized-reaction", mode="reaction", smiles="O", product_smiles="C" * 128, + diagnostic="limit-exceeded") + if args.screenshots: + out = ROOT / "screenshots" + out.mkdir(exist_ok=True) + for name, image in frames.items(): + if name != "combustion-000": + image.save(out / f"{name}.png", optimize=True) + print("All released-host checks passed") + + +if __name__ == "__main__": + main() diff --git a/community/molecule/src/animation.rs b/community/molecule/src/animation.rs new file mode 100644 index 0000000..96926c5 --- /dev/null +++ b/community/molecule/src/animation.rs @@ -0,0 +1,88 @@ +//! Deterministic write-on timing for molecular structures and reaction sides. +pub fn ease(t: f32) -> f32 { + let t = t.clamp(0.0, 1.0); + t * t * (3.0 - 2.0 * t) +} + +fn window(progress: f32, start: f32, end: f32) -> f32 { + ((progress - start) / (end - start)).clamp(0.0, 1.0) +} + +fn slot_start(i: usize, count: usize, last_start: f32) -> f32 { + i as f32 / count.saturating_sub(1).max(1) as f32 * last_start +} + +pub struct Reveal { + pub bonds: Vec, + pub atoms: Vec, +} + +pub const REVEAL_MODES: [&str; 3] = ["bond", "atom", "together"]; + +pub fn structure_reveal( + progress: f32, + bonds: &[(usize, usize)], + atom_count: usize, + reveal_by: &str, +) -> Reveal { + let mut out = Reveal { + bonds: vec![0.0; bonds.len()], + atoms: vec![0.0; atom_count], + }; + match reveal_by { + "together" => { + out.bonds.fill(ease(window(progress, 0.0, 1.0))); + out.atoms.fill(ease(window(progress, 0.0, 0.55))); + } + "atom" => { + let start = |i| slot_start(i, atom_count, 0.53); + for (i, atom) in out.atoms.iter_mut().enumerate() { + *atom = ease(window(progress, start(i), start(i) + 0.24)); + } + for ((a, b), bond) in bonds.iter().copied().zip(&mut out.bonds) { + let ready = start(a.max(b)) + 0.20; + *bond = ease(window(progress, ready, ready + 0.27)); + } + } + _ => { + let mut first = vec![None; atom_count]; + for (i, &(a, b)) in bonds.iter().enumerate() { + let start = slot_start(i, bonds.len(), 0.70); + out.bonds[i] = ease(window(progress, start, start + 0.30)); + first[a].get_or_insert(start); + first[b].get_or_insert(start); + } + for (atom, start) in out.atoms.iter_mut().zip(first) { + let start = start.unwrap_or(0.0); + *atom = ease(window(progress, start, start + 0.18)); + } + } + } + if progress >= 1.0 { + out.bonds.fill(1.0); + out.atoms.fill(1.0); + } + out +} + +pub const REACT_REVEAL_END: f32 = 0.42; +const ARROW_START: f32 = 0.56; +pub const PRODUCT_START: f32 = 0.74; +pub const DIMMED_ALPHA: f32 = 0.70; + +pub struct ReactionPhase { + pub reactant_progress: f32, + pub product_progress: f32, + pub reactant_alpha: f32, + pub arrow: f32, +} + +pub fn reaction_phase(progress: f32) -> ReactionPhase { + let dim = ease(window(progress, REACT_REVEAL_END, ARROW_START)); + ReactionPhase { + reactant_progress: window(progress, 0.0, REACT_REVEAL_END), + product_progress: window(progress, PRODUCT_START, 1.0), + reactant_alpha: 1.0 - (1.0 - DIMMED_ALPHA) * dim, + arrow: ease(window(progress, ARROW_START, PRODUCT_START)), + } +} diff --git a/community/molecule/src/draw.rs b/community/molecule/src/draw.rs new file mode 100644 index 0000000..ad9b3cd --- /dev/null +++ b/community/molecule/src/draw.rs @@ -0,0 +1,402 @@ +//! Vector painting: bonds (single/double/triple, wedge, dash, aromatic +//! circles), host-shaped atom labels with bond trimming, highlights, +//! lone-pair dots, plus signs and the reaction arrow. All emission is a pure +//! function of the geometry and style arguments. +use crate::{Color, DrawCommand, PathVerb, Point, StrokeCap, StrokeJoin, StrokeStyle}; + +use crate::layout::Pt; + +pub fn path_from_points(points: &[Pt]) -> Vec { + let mut out = Vec::with_capacity(points.len() + 1); + for (i, p) in points.iter().enumerate() { + let p = Point { x: p.0, y: p.1 }; + out.push(if i == 0 { + PathVerb::MoveTo(p) + } else { + PathVerb::LineTo(p) + }); + } + out +} + +pub fn lerp(a: Pt, b: Pt, t: f32) -> Pt { + (a.0 + (b.0 - a.0) * t, a.1 + (b.1 - a.1) * t) +} + +fn unit(a: Pt, b: Pt) -> (Pt, f32) { + let (dx, dy) = (b.0 - a.0, b.1 - a.1); + let len = (dx * dx + dy * dy).sqrt(); + if len < 1e-6 { + ((1.0, 0.0), 0.0) + } else { + ((dx / len, dy / len), len) + } +} + +pub fn with_alpha(mut c: Color, alpha: f32) -> Color { + c.a = ((c.a as f32) * alpha.clamp(0.0, 1.0)).round() as u8; + c +} + +fn verb_point(p: Point, scale: f32, dx: f32, dy: f32) -> Point { + Point { + x: p.x * scale + dx, + y: p.y * scale + dy, + } +} + +fn transform_path(path: &[PathVerb], scale: f32, dx: f32, dy: f32) -> Vec { + path.iter() + .map(|v| match *v { + PathVerb::MoveTo(p) => PathVerb::MoveTo(verb_point(p, scale, dx, dy)), + PathVerb::LineTo(p) => PathVerb::LineTo(verb_point(p, scale, dx, dy)), + PathVerb::QuadTo((a, b)) => { + PathVerb::QuadTo((verb_point(a, scale, dx, dy), verb_point(b, scale, dx, dy))) + } + PathVerb::CubicTo((a, b, c)) => PathVerb::CubicTo(( + verb_point(a, scale, dx, dy), + verb_point(b, scale, dx, dy), + verb_point(c, scale, dx, dy), + )), + PathVerb::Close => PathVerb::Close, + }) + .collect() +} + +/// Ink bounding box of a set of contours. +pub fn contours_bbox(paths: &[Vec]) -> Option<(f32, f32, f32, f32)> { + let mut min_x = f32::INFINITY; + let mut min_y = f32::INFINITY; + let mut max_x = f32::NEG_INFINITY; + let mut max_y = f32::NEG_INFINITY; + for path in paths { + for v in path { + let mut include = |p: Point| { + min_x = min_x.min(p.x); + min_y = min_y.min(p.y); + max_x = max_x.max(p.x); + max_y = max_y.max(p.y); + }; + match *v { + PathVerb::MoveTo(p) | PathVerb::LineTo(p) => include(p), + PathVerb::QuadTo((a, b)) => { + include(a); + include(b); + } + PathVerb::CubicTo((a, b, c)) => { + include(a); + include(b); + include(c); + } + PathVerb::Close => {} + } + } + } + if min_x.is_finite() { + Some((min_x, min_y, max_x, max_y)) + } else { + None + } +} + +/// A prepared atom label: merged glyph contours relative to (0,0), ready to +/// translate onto the atom position, plus its half extents for bond trimming. +pub struct Label { + pub contours: Vec, + pub half_w: f32, + pub half_h: f32, +} + +/// Shape `text` through the host engine and center its ink box on the origin. +/// Returns None for empty output (host limit); callers skip the label. +pub fn prepare_label(text: &str, em: f32) -> Option