Visualization

In [1]:
from eminus import Atoms, read, SCF
from eminus.extras import view, view_atoms, view_contour, view_file
In [2]:
# View the initial xyz file
mol = view_file("CH4.xyz")
mol
XYZ file comment: "Experimental geometry from CCCBDB: https://cccbdb.nist.gov/exp2x.asp?casno=74828&charge=0"
NGLWidget()
In [3]:
# Render the view as an image, e.g., to download it
# See the options here: https://nglviewer.org/nglview/latest/api.html#nglview.NGLWidget.render_image
mol_img = mol.render_image()
mol_img.width = "400px"
mol_img
Out[3]:
Image(value=b'', width='400px')
In [4]:
# Create the Atoms object
atoms = Atoms(*read("CH4.xyz"), center=True)
atoms.s = 50
XYZ file comment: "Experimental geometry from CCCBDB: https://cccbdb.nist.gov/exp2x.asp?casno=74828&charge=0"
In [5]:
# The calculations and writing steps have already been done, uncomment them if you want to do them for yourself
# from eminus import USCF, write_cube, write_xyz
# from eminus.extras import get_fods

# Do the DFT calculation
# scf = USCF(atoms)
# scf.run()

# Calculate FODs and write them to a xyz file
# fods = get_fods(scf.atoms)
# write_xyz(scf.atoms, "CH4_fods.xyz", fods)

# Write the density to a cube file
# write_cube(scf, "CH4_density.cube", scf.n)

# One can even display FODs or the density without writing them to files
# view_atoms(scf, fods, plot_n=True)
In [6]:
# View molecule with FODs with the GUI enabled
view_file("CH4_fods.xyz", gui=True)
ThemeManager()
XYZ file comment: "File generated with eminus 2.5.0 on Mon Jul 31 12:23:45 2023"
NGLWidget(gui_style='ngl')
In [7]:
# Display the cube file
view_file("CH4_density.cube")
CUBE file comment: "File generated with eminus 2.5.0 on Mon Jul 31 12:23:45 2023
"
NGLWidget()
In [8]:
# Use a smaller grid and display it along with the atom positions
atoms.s = [10] * 3
atoms.build()
view_atoms(atoms, atoms.r)
In [9]:
# Similar to the `write` method we can also use the `view` method of some classes
atoms.view()
In [10]:
# The view_file function can also handle lists of files
# One can use the view function to call the respective function automatically
view(["CH4_fods.xyz", "CH4_density.cube"]);
interactive(children=(Dropdown(description='filename', options=('CH4_fods.xyz', 'CH4_density.cube'), value='CH…
In [11]:
# Do two identical calculations for different pseudopotentials
atoms1 = Atoms("Li2", [[0, 0, 0], [0, 0, 5]], ecut=5, center=True)
atoms1.Z = 1
scf1 = SCF(atoms1)
scf1.run()
atoms3 = Atoms("Li2", [[0, 0, 0], [0, 0, 5]], ecut=5, center=True)
atoms3.Z = 3
scf3 = SCF(atoms3)
scf3.run();
Start auto minimization...
Method  Iteration  Etot [Eh]    dEtot [Eh]   |Gradient|   
pccg           1   +1.157076    
pccg           2   +0.334852    +8.2222e-01  [+1.40e+02]  
pccg           3   +0.009015    +3.2584e-01  [+1.52e+01]  
pccg           4   -0.206053    +2.1507e-01  [+3.65e+00]  
pccg           5   -0.333330    +1.2728e-01  [+1.04e+00]  
pccg           6   -0.393867    +6.0537e-02  [+2.37e-01]  
pccg           7   -0.419961    +2.6094e-02  [+5.50e-02]  
pccg           8   -0.430345    +1.0384e-02  [+1.74e-02]  
pccg           9   -0.433626    +3.2814e-03  [+5.70e-03]  
pccg          10   -0.434401    +7.7452e-04  [+1.65e-03]  
pccg          11   -0.434619    +2.1832e-04  [+4.72e-04]  
pccg          12   -0.434671    +5.1651e-05  [+1.16e-04]  
pccg          13   -0.434680    +9.6756e-06  [+2.34e-05]  
pccg          14   -0.434682    +1.6292e-06  [+3.99e-06]  
pccg          15   -0.434682    +3.1583e-07  [+7.75e-07]  
pccg          16   -0.434682    +7.3089e-08  [+1.72e-07]  
SCF converged after 16 iterations.
Total SCF time: 0.61556 s
Etot = -0.434682219 Eh
Start auto minimization...
Method  Iteration  Etot [Eh]    dEtot [Eh]   |Gradient|   
pccg           1   +2.722586    
pccg           2   -2.062698    +4.7853e+00  [+1.03e+03]  
pccg           3   -6.855157    +4.7925e+00  [+1.18e+02]  
pccg           4   -8.175438    +1.3203e+00  [+5.20e+00]  
pccg           5   -9.718329    +1.5429e+00  [+1.02e+00]  
pccg           6   -10.008378   +2.9005e-01  [+1.25e-01]  
pccg           7   -10.057063   +4.8686e-02  [+1.80e-02]  
pccg           8   -10.074910   +1.7847e-02  [+6.94e-03]  
pccg           9   -10.085400   +1.0490e-02  [+2.53e-03]  
pccg          10   -10.094884   +9.4838e-03  [+2.27e-03]  
pccg          11   -10.102216   +7.3320e-03  [+2.10e-03]  
pccg          12   -10.107493   +5.2769e-03  [+1.33e-03]  
pccg          13   -10.111811   +4.3179e-03  [+1.05e-03]  
pccg          14   -10.114741   +2.9298e-03  [+7.59e-04]  
pccg          15   -10.116481   +1.7402e-03  [+4.62e-04]  
pccg          16   -10.117599   +1.1182e-03  [+2.76e-04]  
pccg          17   -10.118324   +7.2495e-04  [+1.79e-04]  
pccg          18   -10.118818   +4.9376e-04  [+1.22e-04]  
pccg          19   -10.119134   +3.1606e-04  [+7.93e-05]  
pccg          20   -10.119328   +1.9428e-04  [+5.31e-05]  
pccg          21   -10.119467   +1.3907e-04  [+3.57e-05]  
pccg          22   -10.119551   +8.3723e-05  [+2.33e-05]  
pccg          23   -10.119591   +3.9978e-05  [+1.23e-05]  
pccg          24   -10.119614   +2.3263e-05  [+6.14e-06]  
pccg          25   -10.119630   +1.6095e-05  [+4.25e-06]  
pccg          26   -10.119641   +1.0711e-05  [+2.76e-06]  
pccg          27   -10.119649   +8.0008e-06  [+1.94e-06]  
pccg          28   -10.119656   +6.5719e-06  [+1.50e-06]  
pccg          29   -10.119660   +4.4887e-06  [+1.17e-06]  
pccg          30   -10.119663   +3.0022e-06  [+7.35e-07]  
pccg          31   -10.119665   +1.7290e-06  [+4.81e-07]  
pccg          32   -10.119666   +1.0195e-06  [+2.87e-07]  
pccg          33   -10.119666   +5.4728e-07  [+1.58e-07]  
pccg          34   -10.119667   +2.9706e-07  [+8.43e-08]  
pccg          35   -10.119667   +1.7844e-07  [+5.03e-08]  
pccg          36   -10.119667   +1.0991e-07  [+3.03e-08]  
pccg          37   -10.119667   +6.2502e-08  [+1.66e-08]  
SCF converged after 37 iterations.
Total SCF time: 1.91371 s
Etot = -10.119666979 Eh
In [12]:
# Display the contour lines of the density
# One can see the missing density around the atoms
view_contour(scf1, scf1.n)
In [13]:
# Here one can see the density around the atoms
view_contour(scf3, scf3.n)
In [14]:
# Adjusting the limits of the density gives a more comparable result
view_contour(scf3, scf3.n, limits=(0, 0.02))