Creating a crystal from a CIF & display it in 3D

In this short example you can open a CIF file directly from a filename or an URL, and display it in 3D.

You can also play with the spacegroup and see how that changes the crystal structure.

Note: this requires installing ``ipywidgets`` and ``py3Dmol``

[1]:
from pyobjcryst.crystal import *
from pyobjcryst.atom import Atom
from pyobjcryst.scatteringpower import ScatteringPowerAtom
from math import pi

From IUCr journals

[2]:
c = create_crystal_from_cif("http://scripts.iucr.org/cgi-bin/sendcif?dt3034sup1",
                            oneScatteringPowerPerElement=True,
                            connectAtoms=True)
print(c.GetFormula())
c.widget_3d()
C15 Cl H14 N O S

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol

[2]:

From the Crystallography Open Database

[3]:
c1 = create_crystal_from_cif("http://crystallography.net/cod/4506702.cif",
                            oneScatteringPowerPerElement=True,
                            connectAtoms=True)
print(c1.GetFormula())
c1.widget_3d()
C29 H32 N4 O5

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol

[3]:

Create a Crystal structure and change the spacegroup

[4]:
c = Crystal(5, 5, 5, pi/2, pi/2, pi/2, "P1")
cu = ScatteringPowerAtom("Cu", "Cu")
c.AddScatteringPower(cu)
c.AddScatterer(Atom(0,0,0, "Cu", cu))
c.widget_3d(extra_opacity=0.1, extra_dist=2)

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol

[4]:
[5]:
# Change the spacegroup and update the display
c.ChangeSpaceGroup("Fm-3m")
c.UpdateDisplay()