diff --git a/examples/4 - Interface for pymatgen.ipynb b/examples/4 - Interface for pymatgen.ipynb index 96a9591..d302cfe 100644 --- a/examples/4 - Interface for pymatgen.ipynb +++ b/examples/4 - Interface for pymatgen.ipynb @@ -38,7 +38,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "quick_view(struct)" @@ -47,7 +49,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ "quick_view(struct, conventional=True)" @@ -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": { @@ -95,7 +126,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.8" + "version": "3.8.5" } }, "nbformat": 4, diff --git a/js/package.json b/js/package.json index 170d0ba..6d33216 100644 --- a/js/package.json +++ b/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" diff --git a/jupyter_jsmol/_frontend.py b/jupyter_jsmol/_frontend.py index 1da7dfd..fd95dd4 100644 --- a/jupyter_jsmol/_frontend.py +++ b/jupyter_jsmol/_frontend.py @@ -9,4 +9,4 @@ """ module_name = "jupyter-jsmol" -module_version = "^0.2.5" +module_version = "^0.2.6" diff --git a/jupyter_jsmol/_version.py b/jupyter_jsmol/_version.py index 4f0c45a..301ba82 100644 --- a/jupyter_jsmol/_version.py +++ b/jupyter_jsmol/_version.py @@ -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)) diff --git a/jupyter_jsmol/pymatgen.py b/jupyter_jsmol/pymatgen.py index 6705da8..e34a0f2 100644 --- a/jupyter_jsmol/pymatgen.py +++ b/jupyter_jsmol/pymatgen.py @@ -4,19 +4,36 @@ 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. @@ -24,9 +41,13 @@ def quick_view(structure: Structure, conventional: bool = False, supercell: list 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')) \ No newline at end of file + return JsmolView.from_str(str(cif), supercell_str, *args) diff --git a/setup.py b/setup.py index efd4e25..dc1d134 100644 --- a/setup.py +++ b/setup.py @@ -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',