Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow user to set atom_scales, sticks etc #82

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ viewer.save_image("/home/xing/filename.png")
viewer.download_image("filename.png")
```

### Different styles for the atoms.


<img src="docs/source/_static/images/example-custom-model-style.png" width="500px"/>



### Visualizing crystal structures
For a nice visualization of a crystal, show
- unit cell
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ function render({ model, el }) {
editor = new weas.WEAS({ domElement, atoms, viewerConfig, guiConfig });
// window.editor = editor; // for debugging
editor.avr.selectedAtomsIndices = model.get("selectedAtomsIndices");
// editor.avr.atomScales = model.get("atomScales");
// editor.avr.modelSticks = model.get("modelSticks");
// editor.avr.modelPolyhedras = model.get("modelPolyhedras");
// species settings
editor.avr.atomManager.fromSettings(model.get("speciesSettings"));
// bond settings
Expand All @@ -82,6 +79,16 @@ function render({ model, el }) {
// vector field
editor.avr.VFManager.fromSettings(model.get("vectorField"));
editor.avr.showVectorField = model.get("showVectorField");
// if the atomScales is not a empty array, then update the atomScales
if (model.get("atomScales").length > 0) {
editor.avr.atomScales = model.get("atomScales");
}
if (model.get("modelSticks").length > 0) {
editor.avr.modelSticks = model.get("modelSticks");
}
if (model.get("modelPolyhedras").length > 0) {
editor.avr.modelPolyhedras = model.get("modelPolyhedras");
}
editor.avr.drawModels();
// mesh primitives
editor.instancedMeshPrimitive.fromSettings(model.get("instancedMeshPrimitive"));
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"dat.gui": "^0.7.9",
"three": "^0.161.0",
"weas": ">=0.1.34"
"weas": ">=0.1.36"
},
"devDependencies": {
"esbuild": "^0.20.0"
Expand Down
4 changes: 0 additions & 4 deletions src/weas_widget/atoms_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ def atoms(self, atoms):
# initialize atomScales
if isinstance(atoms, list):
atoms = atoms[0]
natom = len(atoms["symbols"])
self._widget.atomScales = [1] * natom
self._widget.modelSticks = [0] * natom
self._widget.modelPolyhedras = [0] * natom
# species
self.species.update_atoms()
# bond
Expand Down
36 changes: 18 additions & 18 deletions src/weas_widget/base_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class BaseWidget(anywidget.AnyWidget):
ready = tl.Bool(False).tag(sync=True)
logLevel = tl.Unicode("info").tag(sync=True)
# atoms can be a dictionary or a list of dictionaries
atoms = tl.Union([tl.Dict({}), tl.List(tl.Dict({}))]).tag(sync=True)
selectedAtomsIndices = tl.List([]).tag(sync=True)
atoms = tl.Union([tl.Dict(), tl.List(tl.Dict())]).tag(sync=True)
selectedAtomsIndices = tl.List().tag(sync=True)
boundary = tl.List([[0, 1], [0, 1], [0, 1]]).tag(sync=True)
modelStyle = tl.Int(0).tag(sync=True)
# color
Expand All @@ -34,44 +34,44 @@ class BaseWidget(anywidget.AnyWidget):
showBondedAtoms = tl.Bool(False).tag(sync=True)
showHydrogenBonds = tl.Bool(False).tag(sync=True)
hideLongBonds = tl.Bool(True).tag(sync=True)
atomScales = tl.List([]).tag(sync=True)
modelSticks = tl.List([]).tag(sync=True)
modelPolyhedras = tl.List([]).tag(sync=True)
atomScales = tl.List().tag(sync=True)
modelSticks = tl.List().tag(sync=True)
modelPolyhedras = tl.List().tag(sync=True)
volumetricData = tl.Dict({"values": [[[]]]}).tag(sync=True)
imageData = tl.Unicode("").tag(sync=True)
vectorField = tl.Dict().tag(sync=True)
showVectorField = tl.Bool(True).tag(sync=True)
guiConfig = tl.Dict({}).tag(sync=True)
guiConfig = tl.Dict().tag(sync=True)
# animation
currentFrame = tl.Int(0).tag(sync=True)
# instanced mesh primitives
instancedMeshPrimitive = tl.List(tl.Dict({})).tag(sync=True)
instancedMeshPrimitive = tl.List(tl.Dict()).tag(sync=True)
# any mesh
anyMesh = tl.List(tl.Dict({})).tag(sync=True)
anyMesh = tl.List(tl.Dict()).tag(sync=True)
# viewer
viewerStyle = tl.Dict({}).tag(sync=True)
viewerStyle = tl.Dict().tag(sync=True)
# camera
cameraSetting = tl.Dict({}).tag(sync=True)
cameraSetting = tl.Dict().tag(sync=True)
cameraZoom = tl.Float().tag(sync=True)
cameraPosition = tl.List().tag(sync=True)
cameraRotation = tl.List().tag(sync=True)
cameraLookAt = tl.List().tag(sync=True)
# task
js_task = tl.Dict({}).tag(sync=True)
python_task = tl.Dict({}).tag(sync=True)
js_task = tl.Dict().tag(sync=True)
python_task = tl.Dict().tag(sync=True)
debug = tl.Bool(False).tag(sync=True)
# species
speciesSettings = tl.Dict({}).tag(sync=True)
speciesSettings = tl.Dict().tag(sync=True)
# bond
bondSettings = tl.Dict({}).tag(sync=True)
bondSettings = tl.Dict().tag(sync=True)
# isosurface
isoSettings = tl.Dict({}).tag(sync=True)
isoSettings = tl.Dict().tag(sync=True)
# volume slice
sliceSettings = tl.Dict({}).tag(sync=True)
sliceSettings = tl.Dict().tag(sync=True)
# phonon
phonon = tl.Dict({}).tag(sync=True)
phonon = tl.Dict().tag(sync=True)
# highlight
highlightSettings = tl.Dict({}).tag(sync=True)
highlightSettings = tl.Dict().tag(sync=True)
#
showAtomLegend = tl.Bool(False).tag(sync=True)

Expand Down
23 changes: 22 additions & 1 deletion tests/notebooks/tests/notebooks/widgets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,32 @@
"viewer.avr.model_style = 1\n",
"viewer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# set scale and style for each atom\n",
"from ase.build import molecule, fcc111\n",
"from weas_widget import WeasWidget\n",
"mol = molecule(\"C2H6SO\")\n",
"slab = fcc111(\"Pt\", size=(2, 2, 3), vacuum=5)\n",
"mol.translate(slab[-1].position - mol[0].position + [0, 0, 2])\n",
"slab += mol\n",
"viewer = WeasWidget()\n",
"viewer.from_ase(slab)\n",
"viewer.camera.setting = {\"direction\": [0, -1, 0], \"zoom\": 1.0}\n",
"viewer.avr.model_style = 1\n",
"viewer.avr.atom_scales = [1 if atom.symbol == \"Pt\" else 0.4 for atom in slab]\n",
"viewer"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "aiida",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading