Skip to content

Commit

Permalink
Merge pull request #21 from fekad/spacegroup
Browse files Browse the repository at this point in the history
using args and kwargs fot the quickview method
  • Loading branch information
fekad committed Jan 28, 2021
2 parents 900293b + 7951435 commit 90abe6e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
39 changes: 35 additions & 4 deletions examples/4 - Interface for pymatgen.ipynb
Expand Up @@ -38,7 +38,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"quick_view(struct)"
Expand All @@ -47,7 +49,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"quick_view(struct, conventional=True)"
Expand All @@ -71,12 +75,39 @@
"quick_view(struct, conventional=True, supercell=[2,2,2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using extra parameters"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All positional arguments will be passed to jsmol's load command."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"quick_view(struct, \"packed\", conventional=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"?quick_view"
]
}
],
"metadata": {
Expand All @@ -95,7 +126,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
@@ -1,6 +1,6 @@
{
"name": "jupyter-jsmol",
"version": "0.2.5",
"version": "0.2.6",
"author": {
"name": "Adam Fekete",
"email": "adam@fekete.co.uk"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_jsmol/_frontend.py
Expand Up @@ -9,4 +9,4 @@
"""

module_name = "jupyter-jsmol"
module_version = "^0.2.5"
module_version = "^0.2.6"
2 changes: 1 addition & 1 deletion jupyter_jsmol/_version.py
Expand Up @@ -4,5 +4,5 @@
# Copyright (c) Adam Fekete.
# Distributed under the terms of the Modified BSD License.

version_info = (0, 2, 5)
version_info = (0, 2, 6)
__version__ = ".".join(map(str, version_info))
35 changes: 28 additions & 7 deletions jupyter_jsmol/pymatgen.py
Expand Up @@ -4,29 +4,50 @@
try:
from pymatgen import Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.io.cif import CifWriter

pymatgen_loaded = True
except ImportError:
raise RuntimeError('To use quick_view, you need to have pymatgen installed.')
raise RuntimeError("To use quick_view, you need to have pymatgen installed.")

from jupyter_jsmol import JsmolView

def quick_view(structure: Structure, conventional: bool = False, supercell: list = None) -> JsmolView:

def quick_view(
structure: Structure,
*args,
conventional: bool = False,
supercell: list = [1, 1, 1],
symprec: float = 0.01,
angle_tolerance: float = 5.0
) -> JsmolView:
"""A function to visualize pymatgen Structure objects in jupyter notebook using jupyter_jsmol package.
Args:
structure: pymatgen Structure object.
*args: Extra arguments for JSmol's load command. Eg. "{2 2 2}", "packed"
conventional: use conventional cell. Defaults to False.
transform: can be used to make supercells with pymatgen.Structure.make_supercell method.
supercell: can be used to make supercells with pymatgen.Structure.make_supercell method.
symprec: If not none, finds the symmetry of the structure
and writes the cif with symmetry information. Passes symprec
to the SpacegroupAnalyzer.
angle_tolerance: Angle tolerance for symmetry finding. Passes
angle_tolerance to the SpacegroupAnalyzer. Used only if symprec
is not None.
Returns:
A jupyter widget object.
"""

s = structure.copy()
if conventional:
s = SpacegroupAnalyzer(s).get_conventional_standard_structure()
spga = SpacegroupAnalyzer(s, symprec=symprec, angle_tolerance=angle_tolerance)
s = spga.get_conventional_standard_structure()

cif = CifWriter(
s, symprec=symprec, angle_tolerance=angle_tolerance, refine_struct=False
)

if supercell:
s.make_supercell(supercell)
supercell_str = "{" + " ".join(map(str, supercell)) + "}"

return JsmolView.from_str(s.to('cif'))
return JsmolView.from_str(str(cif), supercell_str, *args)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@
description='JSmol viewer widget for Jupyter',
long_description=long_description,
long_description_content_type="text/markdown",
version='0.2.5',
version='0.2.6',
author='Adam Fekete',
author_email='adam@fekete.co.uk',
url='https://github.com/fekad/jupyter-jsmol',
Expand Down

0 comments on commit 90abe6e

Please sign in to comment.