#!/usr/bin/env python # coding: utf-8 # # Tutorial 1: Atomic crystal module in PyXtal # # Source code: https://github.com/qzhu2017/PyXtal # # Created by Qiang Zhu (2020/11/23) # # Last updated: 2022/08/11 # # More details can be found at the following [link](https://pyxtal.readthedocs.io/en/latest/) # # # 1.1 Generate a random atomic crystal # In[1]: from pyxtal import pyxtal # In[2]: C1 = pyxtal() C1.from_random(3, 227, ['C'], [8]) # Alternative, you can also generate the structure with pre-assigned sites # C1.from_random(3, 225, ["C"], [12], sites=[["4a", "8c"]]) print(C1) # In[3]: C1.atom_sites[0].wp # In[4]: #display the structure can be easily accessed with the show() function C1.show(supercell=(2,2,1)) # # 1.2 Manipulating the crystal via symmetry relation # In[5]: # lower the symmetry from cubic to tetragonal C2 = C1.subgroup_once(H=141, eps=1e-2) print(C2) # In[6]: # Compute the XRD xrd1 = C1.get_XRD() xrd2 = C2.get_XRD() # In[7]: # Compare two structures by XRD from pyxtal.XRD import Similarity p1 = xrd1.get_profile() p2 = xrd2.get_profile() s = Similarity(p1, p2, x_range=[15, 90]) print(s) s.show() # # 1.3 Chemical substitution via symmetry relation # In[8]: #play substitution permutation = {"C":"Si"} SiC = C1.subgroup_once(eps=0.01, H=None, perms=permutation) print(C1) print(SiC) SiC.show(supercell=(2,2,2)) # # 1.4 Supergroup symmetry # In[9]: # load the experimental alpha-quartz structure from the cif file lt_sio2 = pyxtal() lt_sio2.from_seed('lt_quartz.cif') print(lt_sio2) lt_sio2.show() # In[10]: # Here we search for the high temperature phase ht_sio2, _ = lt_sio2.supergroup(G=180) print(len(ht_sio2), 'structures have been generated') print(ht_sio2[-1]) ht_sio2[-1].show() # # 1.5 Exporting the structure # In[11]: #In general, you can export the structure in several ways # CIF/POSCAR file C1.to_file('1.cif') C1.to_ase().write('1.vasp', format='vasp', vasp5=True) # ASE's atoms object ase_struc = C1.to_ase() print(ase_struc) # Pymatgen object pmg_struc = C1.to_pymatgen() print(pmg_struc) # # 1.6 Low dimensional systems # In[12]: # An example to generate 2D atomic crystal C3 = pyxtal() C3.from_random(2, 75, ['C'], [6], thickness=0.0) C3.show(scale=0.2) # In[13]: # An example to generate 0D atomic cluster C4 = pyxtal() C4.from_random(0, 'Ih', ['C'], [60]) C4.show(scale=0.2) # In[14]: # to improve the quality, you can increase the minimum distance C4.from_random(0, 'Ih', ['C'], [60], t_factor=1.2) C4.show(scale=0.1, radius=0.01)