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

Use refactored weas #47

Merged
merged 19 commits into from
Apr 5, 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
54 changes: 46 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ For a nice visualization of a crystal, show
from weas_widget import WeasWidget
viewer1 = WeasWidget()
viewer1.load_example("tio2.cif")
viewer1.modelStyle = 2
viewer1.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer1.showBondedAtoms = True
viewer1.colorType = "VESTA"
viewer1.avr.model_style = 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pointing out that the meaning of avr is not intuitively clear to me

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's AtomsViewer 😆 . I am thinking of three names:

  • viewer.avr.model_style=1
  • viewer.atoms_viewer.model_style=1
  • viewer.atoms.model_style=1
    Which one do you think is better? Or any other names?

BTW, tor the moment, the widget has three top-level attributes:

  • avr: AtomsViewer,
  • camera
  • imp: InstancedMeshPrimitive
    In the future, we will add
  • light
  • ops: Operators, e.g., viewer.ops.objects.delete()
  • scene, access all objects in the scene.

Copy link
Collaborator

@ltalirz ltalirz Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for the option viewer.atoms in that case

camera, scene and light are self-explanatory.
imp is not - perhaps mesh?
ops is also not so clear to me (it would usually stand for "operations" as in FLOPS) - will there be other properties besides objects? (if not, objects could be a top-level attribute)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I need to think about this more; Most names come directly from the JavaScript part. I need to make sure the names are good on both sides.

viewer1.avr.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer1.avr.show_bonded_atoms = True
viewer1.avr.color_type = "VESTA"
viewer1
```

Expand All @@ -131,8 +131,8 @@ from ase.io.cube import read_cube_data
volume, atoms = read_cube_data("h2o-homo.cube")
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.volumetricData = {"values": volume}
viewer.isoSettings = [{"isovalue": 0.0001, "mode": 0}]
viewer.avr.iso.volumetric_data = {"values": volume}
viewer.avr.iso.settings = [{"isovalue": 0.0001, "mode": 0}]
viewer
```
<img src="docs/source/_static/images/example-isosurface.png" width="300px"/>
Expand All @@ -150,7 +150,7 @@ atoms*=[2, 2, 1]
atoms.set_array("moment", np.ones(len(atoms)))
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.modelStyle = 1
viewer.avr.model_style = 1
viewer
```
<img src="docs/source/_static/images/example-magnetic-moment.png" width="300px"/>
Expand All @@ -171,14 +171,52 @@ trajectory = generate_phonon_trajectory(atoms, eigenvector, repeat=[4, 4, 1])
viewer = WeasWidget()
viewer.from_ase(trajectory)
# set a vector field to show the arrow
viewer.vectorField = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer.avr.vf.settings = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer.avr.vf.show = True
viewer
```

<img src="docs/source/_static/images/example-phonon.gif" width="300px"/>



## Test

### Unit test

```console
pytest
```

### End-to-end test

The e2e test is similar to [ipywidgets](https://ipywidgets.readthedocs.io/en/latest/dev_testing.html).

For the first time, one needs to install the dependence.

```
cd tests/notebooks/
yarn install
```

Then run in a terminal:

```
yarn start
```

In another terminal:

```
yarn test
```

If the snapshots need to be updated:

```
yarn test:update
```

## Contact
* Xing Wang <xingwang1991@gmail.com>

Expand Down
10 changes: 4 additions & 6 deletions docs/source/boundary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ Show the atoms on the unit cell:

.. code-block:: python

viewer.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer.modelStyle = 1
viewer.drawModels()
viewer.avr.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer.avr.model_style = 1


Create a supercell:

.. code-block:: python

viewer.boundary = [[-1, 2], [-1, 2], [-1, 2]]
viewer.modelStyle = 1
viewer.drawModels()
viewer.avr.boundary = [[-1, 2], [-1, 2], [-1, 2]]
viewer.avr.model_style = 1
28 changes: 24 additions & 4 deletions docs/source/camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,35 @@
Camera
===================

Setting
=============
The camera can be configured in two ways:

Direct Camera Settings
=======================

The camera has three direct settings:

- **zoom**: Controls the zoom level of the camera.
- **position**: Specifies the camera's position in 3D space.
- **look_at**: Determines the point in space the camera is oriented towards.

One can set the direction and zoom of the camera:
Example usage:

.. code-block:: python

viewer.cameraSetting = {"direction": [0, 5, 1], "zoom": 2}
viewer.camera.zoom = 2
viewer.camera.position = [0, 0, 100]
viewer.camera.look_at = [0, 0, 0]

Viewpoint-Centric Settings
===========================
This approach is useful for orienting the camera towards a subject, like the center of atoms or a bounding box, based on direction and distance from the subject.
This method automatically calculates the appropriate `position` and `look_at`` values.

.. code-block:: python

# Direction is relative to the center of atoms or bounding box.
# Distance specifies how far the camera is from the look_at point.
viewer.camera.setting = {"direction": [0, 5, 1], "distance": 50, "zoom": 2}
ltalirz marked this conversation as resolved.
Show resolved Hide resolved

Camera Type
=============
Expand Down
6 changes: 3 additions & 3 deletions docs/source/color.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Here we show how to color the atoms by their forces.

viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.colorBy = "Force"
viewer.colorRamp = ["red", "yellow", "blue"]
viewer.modelStyle = 1
viewer.avr.color_by = "Force"
viewer.avr.color_ramp = ["red", "yellow", "blue"]
viewer.avr.model_style = 1
viewer


Expand Down
4 changes: 2 additions & 2 deletions docs/source/isosurface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Here is an example of drawing isosurfaces for HOMO of H2O molecule.
volume, atoms = read_cube_data("h2o-homo.cube")
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.volumetricData = {"values": volume}
viewer.isoSettings = [{"isovalue": 0.0001, "mode": 0}]
viewer.avr.iso.volumetric_data = {"values": volume}
viewer.avr.iso.settings = [{"isovalue": 0.0001, "mode": 0}]
viewer

.. figure:: _static/images/example-isosurface.png
Expand Down
2 changes: 1 addition & 1 deletion docs/source/mesh_primitive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The following example shows how to use the mesh primitive to draw two cubes and
},
]

viewer.meshPrimitives = data
viewer.imp.settings = data
viewer


Expand Down
36 changes: 18 additions & 18 deletions docs/source/quick_start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@
"outputs": [],
"source": [
"# ball and stick\n",
"viewer.modelStyle = 1\n",
"viewer.drawModels()"
"viewer.avr.model_style = 1"
]
},
{
Expand All @@ -141,8 +140,8 @@
"outputs": [],
"source": [
"# only draw stick (bond) for first four atoms\n",
"viewer.modelSticks = [1, 1, 1, 1, 0, 0, 0, 0]\n",
"viewer.drawModels()"
"viewer.model_sticks = [1, 1, 1, 1, 0, 0, 0, 0]\n",
"viewer.avr.draw()"
]
},
{
Expand All @@ -162,8 +161,8 @@
},
"outputs": [],
"source": [
"viewer.atomScales = [1, 1, 1, 1, 1, 0.6, 0.6, 0.6, 1.5, 1.5]\n",
"viewer.drawModels()"
"viewer.avr.atom_scales = [1, 1, 1, 1, 1, 0.6, 0.6, 0.6, 1.5, 1.5]\n",
"viewer.avr.draw()"
]
},
{
Expand All @@ -184,7 +183,7 @@
},
"outputs": [],
"source": [
"viewer.selectedAtomsIndices"
"viewer.avr.selected_atoms_indices"
]
},
{
Expand All @@ -202,7 +201,7 @@
"metadata": {},
"outputs": [],
"source": [
"viewer.selectedAtomsIndices = [0, 1, 2]"
"viewer.avr.selected_atoms_indices = [0, 1, 2]"
]
},
{
Expand All @@ -229,13 +228,13 @@
"viewer1 = WeasWidget()\n",
"viewer1.load_example(\"tio2.cif\")\n",
"# show polyhedra\n",
"viewer1.modelStyle = 2\n",
"viewer1.avr.model_style = 2\n",
"# show boundary atoms\n",
"viewer1.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]\n",
"viewer1.avr.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]\n",
"# show bonded atoms outside the cell\n",
"viewer1.showBondedAtoms = True\n",
"viewer1.avr.show_bonded_atoms = True\n",
"# Change color tyoe to \"VESTA\"\n",
"viewer1.colorType = \"VESTA\"\n",
"viewer1.avr.color_type = \"VESTA\"\n",
"viewer1"
]
},
Expand Down Expand Up @@ -308,10 +307,10 @@
"volume, atoms = read_cube_data(\"../../examples/h2o-homo.cube\")\n",
"viewer = WeasWidget()\n",
"viewer.from_ase(atoms)\n",
"viewer.volumetricData = {\"values\": volume}\n",
"viewer.avr.iso.volumetric_data = {\"values\": volume}\n",
"# mode 0: plot both positive and negative isosurface for the isovalue\n",
"# mode !=0, only plot one isosurface\n",
"viewer.isoSettings = [{\"isovalue\": 0.0001, \"mode\": 0}]\n",
"viewer.avr.iso.settings = [{\"isovalue\": 0.0001, \"mode\": 0}]\n",
"viewer"
]
},
Expand Down Expand Up @@ -340,7 +339,8 @@
"atoms.set_array(\"moment\", np.ones(len(atoms)))\n",
"viewer = WeasWidget()\n",
"viewer.from_ase(atoms)\n",
"viewer.modelStyle = 1\n",
"viewer.avr.model_style = 1\n",
"viewer.camera.setting = {\"direction\": [0, -1, 0]}\n",
"viewer"
]
},
Expand All @@ -363,7 +363,7 @@
"origins = atoms.positions\n",
"# the vertor\n",
"vectors = [[0, 0, 1]]*len(atoms)\n",
"viewer.vectorField = [{\"origins\": origins, \"vectors\": vectors, \"color\": \"red\"}]"
"viewer.avr.vf.settings = [{\"origins\": origins, \"vectors\": vectors, \"color\": \"red\"}]"
]
},
{
Expand Down Expand Up @@ -395,7 +395,7 @@
"viewer = WeasWidget()\n",
"viewer.from_ase(trajectory)\n",
"# set a vector field to show the arrow\n",
"viewer.vectorField = [{\"origins\": \"positions\", \"vectors\": \"movement\", \"radius\": 0.1}]\n",
"viewer.avr.vf.settings = [{\"origins\": \"positions\", \"vectors\": \"movement\", \"radius\": 0.1}]\n",
"viewer"
]
},
Expand All @@ -420,7 +420,7 @@
"One can set the direction and zoom of the camera:\n",
"\n",
"```python\n",
"viewer.cameraSetting = {\"direction\": [0, 5, 1], \"zoom\": 2}\n",
"viewer.camera.setting = {\"direction\": [0, 5, 1], \"zoom\": 2}\n",
"```\n"
]
},
Expand Down
4 changes: 2 additions & 2 deletions docs/source/vector_field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Show the magnetic moment as a vector field.
atoms.set_array("moment", np.ones(len(atoms)))
viewer = WeasWidget()
viewer.from_ase(atoms)
viewer.modelStyle = 1
viewer.avr.model_style = 1
viewer

.. figure:: _static/images/example-magnetic-moment.png
Expand All @@ -43,7 +43,7 @@ One can visualize the phonon dispersion via lattice vibrations. One only need to
viewer = WeasWidget()
viewer.from_ase(trajectory)
# set a vector field to show the arrow
viewer.vectorField = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer.avr.vf.settings = [{"origins": "positions", "vectors": "movement", "radius": 0.1}]
viewer


Expand Down
Loading
Loading