This tutorial discusses how to convert the crystal packing into spherical images. From the image representation, we will show how to measure the crystal packing similarity. More details about this approach can be found in https://arxiv.org/abs/2207.12548
Created by Qiang Zhu (2022/07/27)
Last updated: 2022/08/11
# Load the crystals
from pyxtal import pyxtal
from pkg_resources import resource_filename
cif_ben = resource_filename("pyxtal", "database/cifs/benzene.cif")
cif_naph = resource_filename("pyxtal", "database/cifs/naphthalene.cif")
cif_anth = resource_filename("pyxtal", "database/cifs/anthracene.cif")
#benzene
ben = pyxtal(molecular=True)
ben.from_seed(cif_ben, ['benzene'])
#naphthalene
naph = pyxtal(molecular=True)
naph.from_seed(cif_naph, ['naphthalene'])
#anthracene
anth = pyxtal(molecular=True)
anth.from_seed(cif_anth, ['anthracene'])
# Compute and display the image describing benzene's crystal packing
sph_ben = ben.get_spherical_images()
sph_ben.align()
sph_ben.plot_sph_images()
# One can rotate the image and using different lmax as well
sph_ben.rotate(0, 0, -40)
sph_ben.plot_sph_images(lmax=10)
# view the molecular packing at the real space
sph_ben.plot_real_image(0)
Number of neighboring molecules 30 [-2.041 -2.041 -2.041 -2.041 -1.325 -1.325 -1.325 -1.325 -1.127 -1.127 -1.127 -1.127 -0.363 -0.363 -0.224 -0.224 -0.075 -0.075 -0.075 -0.075 -0.067 -0.067 -0.067 -0.067 -0.067 -0.067 -0.061 -0.061 -0.061 -0.061]
============================== *** Open Babel Error in LoadAllPlugins Unable to find OpenBabel plugins. Try setting the BABEL_LIBDIR environment variable.
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
<py3Dmol.view at 0x7fe3dcaae890>
# Compute and display the image describing naphthalene and anthracene
sph_naph = naph.get_spherical_images()
sph_naph.align()
sph_naph.plot_sph_images()
sph_anth = anth.get_spherical_images()
sph_anth.align()
sph_anth.plot_sph_images()
# One can clearly see the strong similarity between naph and anth
# To further comfirm it, one can simply compute the similarity as defined in
# https://arxiv.org/abs/2207.12548
s1 = sph_naph.get_similarity(sph_ben)
s2 = sph_naph.get_similarity(sph_anth)
print('Similarity between benzen and naphta', s1[0,0])
print('Similarity between antcen and naphta', s2[0,0])
Similarity between benzen and naphta 0.7145885464284113 Similarity between antcen and naphta 0.9742268926829936