qharv.inspect package¶
Submodules¶
qharv.inspect.axes_elem_pos module¶
-
qharv.inspect.axes_elem_pos.
ase_atoms
(axes, elem, pos, **kwargs)[source]¶ create ase Atoms object
- Parameters
axes (np.array) – lattice vectors in row-major
elem (np.array) – chemical symbols
pos (np.array) – atomic positions
- Returns
Atoms object
- Return type
ase.Atoms
-
qharv.inspect.axes_elem_pos.
ase_read
(floc)[source]¶ use atomic simulation environment (ase) package to read file can read any format ase.read supports
- Parameters
floc (str) – file location of structure file (e.g. struct.xsf)
- Returns
with [‘axes’, ‘elem’, ‘pos’] entries
- Return type
dict
-
qharv.inspect.axes_elem_pos.
ase_tile
(axes, elem, pos, tmat)[source]¶ use ase to tile supercell
- Parameters
axes (np.array) – lattice vectors in row-major
elem (np.array) – chemical symbols
pos (np.array) – atomic positions
tmat (np.array) – tiling matrix (a.k.a. supercell matrix)
- Returns
supercell (‘axes’, ‘elem’, ‘pos’)
- Return type
(np.array, np.array, np.array)
-
qharv.inspect.axes_elem_pos.
make_atoms
(axes, posl, eleml=None, **kwargs)[source]¶ create ase Atoms object using arbitrary element names
- Parameters
axes (np.array) – lattice vectors in row-major
posl (list) – a list of atomic positions, each a np.array
eleml (list, optional) – a list of chemical symbols
- Returns
Atoms object
- Return type
ase.Atoms
qharv.inspect.axes_pos module¶
-
qharv.inspect.axes_pos.
abc
(axes)[source]¶ a,b,c lattice parameters
- Parameters
axes (np.array) – lattice vectors in row-major
- Returns
lattice vector lengths
- Return type
np.array
-
qharv.inspect.axes_pos.
ase_get_spacegroup_id
(axes, elem, pos, **kwargs)[source]¶ get space group ID using atomic simulation environment
- Parameters
axes (np.array) – lattice vectors
elem (np.array) – atomic symbols
pos (np.array) – atomic positions
-
qharv.inspect.axes_pos.
auto_distance_table
(axes, pos, dn=1)[source]¶ calculate distance table of a set of particles among themselves keep this function simple! use this to test distance_table(axes,pos1,pos2)
- Parameters
axes (np.array) – lattice vectors in row-major
pos (np.array) – particle positions in row-major
dn (int,optional) – number of neighboring cells to search in each direction
- Returns
dtable shape=(natom,natom), where natom=len(pos)
- Return type
np.array
-
qharv.inspect.axes_pos.
c_over_a
(axes, cmax=True, warn=True, abtol=1e-06)[source]¶ calculate c/a ratio given a=b
- Parameters
axes (np.array) – lattice vectors
cmax (bool,optional) – c vector is longest
- Returns
c/a
- Return type
float
-
qharv.inspect.axes_pos.
cubic_pos
(nx, ndim=3)[source]¶ initialize simple cubic lattice in unit cube
- Parameters
nx (int) OR nxnynz (np.array) – number of points along each dimension
ndim (int) – number of spatial dimensions
- Returns
simple cubic lattice positions, shape (nx**3, ndim)
- Return type
np.array
-
qharv.inspect.axes_pos.
dimer_pairs_and_dists
(axes, pos, rmax, rmin=0)[source]¶ find all dimers within a separtion of (rmin,rmax)
- Parameters
axes (np.array) – crystal lattice vectors
pos (np.array) – particle positions
rmax (float) – maximum dimer separation
rmin (float,optional) – minimum dimer separation
- Returns
unique pairs, a list of (int,int) particle id pairs np.array: unique distances, a list of floats
- Return type
np.array
-
qharv.inspect.axes_pos.
dimer_rep
(atoms, rmax=inf, rmin=0.0, sort_id=False, return_pairs=False)[source]¶ Find dimer representation of atoms
- Parameters
atoms (ase.Atoms) – one-component system
rmax (float, optional) – maximum dimer separation, default np.inf
return_pairs (bool, optional) – return indices of dimers, default False
- Returns
- (com, avecs), center of mass and
half-bond vector, one for each dimer
- Return type
(np.array, np.array)
-
qharv.inspect.axes_pos.
displacement
(axes, spos1, spos2, dn=1)[source]¶ single particle displacement spos1-spos2 under minimum image convention
- Parameters
axes (np.array) – lattice vectors
spos1 (np.array) – single particle position 1
spos2 (np.array) – single particle position 2
dn (int,optional) – number of neighboring cells to search in each direction
- Returns
disp_table shape=(natom,natom,ndim)
- Return type
np.array
-
qharv.inspect.axes_pos.
find_dimers
(rij, rmax=inf, rmin=0, sort_id=False)[source]¶ find all dimers within a separtion of (rmin, rmax)
- Parameters
rij (np.array) – distance table
rmax (float, optional) – maximum dimer separation, default np.inf
rmin (float, optional) – minimum dimer separation, default 0
sort_id (bool, optional) – sort pair by first atom id, default false
- Returns
unique pairs, a list of (int, int) particle id pairs
- Return type
np.array
-
qharv.inspect.axes_pos.
get_nvecs
(axes, pos, atol=1e-10)[source]¶ find integer vectors of lattice positions from unit cell
- Parameters
axes (np.array) – lattice vectors in row-major
pos (np.array) – lattice sites
- Returns
nvecs, integer vectors that label the lattice sites
- Return type
np.array
Example
>>> nvecs = get_nvecs(axes, pos)
-
qharv.inspect.axes_pos.
pos_in_axes
(axes, pos, ztol=1e-10)[source]¶ particle position(s) in cell
- Parameters
axes (np.array) – crystal lattice vectors
pos (np.array) – particle position(s)
- Returns
particle position(s) inside the cell
- Return type
pos0(np.array)
-
qharv.inspect.axes_pos.
raxes
(axes)[source]¶ find reciprocal lattice vectors
- Parameters
axes (np.array) – lattice vectors in row-major
- Returns
raxes, reciprocal lattice vectors in row-major
- Return type
np.array
-
qharv.inspect.axes_pos.
rins
(axes)[source]¶ radius of the inscribed sphere inside the given cell
- Parameters
axes (np.array) – lattice vectors in row-major
- Returns
radius of the inscribed sphere
- Return type
float
-
qharv.inspect.axes_pos.
rs
(axes, natom)[source]¶ rs density parameter (!!!! axes MUST be in units of bohr)
- Parameters
axes (np.array) – lattice vectors in row-major, MUST be in units of bohr
- Returns
volume of cell
- Return type
float
-
qharv.inspect.axes_pos.
rwsc
(axes, dn=1)[source]¶ radius of the inscribed sphere inside the real-space Wigner-Seitz cell of the given cell
- Parameters
axes (np.array) – lattice vectors in row-major
dn (int,optional) – number of image cells to search in each dimension, default dn=1 searches 26 images in 3D.
- Returns
Wigner-Seitz cell radius
- Return type
float
-
qharv.inspect.axes_pos.
tmat
(axes0, axes1)[source]¶ calculate the tiling matrix that takes axes0 to axes
- Parameters
axes0 (np.array) – primitive cell lattice vectors in row-major
axes1 (np.array) – supercell lattice vectors in row-major
- Returns
tmat, such that axes1 = np.dot(tmat, axes0)
- Return type
np.array
qharv.inspect.box_pos module¶
-
qharv.inspect.box_pos.
disp_in_box
(drij, box)[source]¶ Enforce minimum image convention (MIC) on displacement vectors.
- Parameters
drij (np.array) – ri - rj for all pairs of particles rij
box (float) – side lengths of box
- Returns
displacement vectors under MIC.
- Return type
np.array
-
qharv.inspect.box_pos.
displacement_table
(pos, box)[source]¶ Calculate displacements ri-rj between all pairs of particles.
- Parameters
pos (np.array) – particle positions
box (float) – side lengths of box
- Returns
- drij, a table of displacement vectors under MIC,
shape (natom, natom, ndim)
- Return type
np.array
-
qharv.inspect.box_pos.
pos_in_box
(pos, box)[source]¶ Enforce periodic bounary condition (PBC) on particle positions. Simulation box contains [0, Lx)x[0, Ly)x[0, Lz)
- Parameters
pos (np.array) – particle positions under open boundary conditions.
box (float) – side lengths of box
- Returns
particle positions under periodic bounary conditions.
- Return type
np.array
qharv.inspect.crystal module¶
-
qharv.inspect.crystal.
atomic_coords
(fname, pset='ion0')[source]¶ extract atomic positions from QMCPACK input similar to ase.Atoms.get_positions()
- Parameters
fname (str) – xml input filename
- Returns
axes
- Return type
np.array
-
qharv.inspect.crystal.
draw_atoms
(ax, pos, **kwargs)[source]¶ draw atoms on ax see example in draw_crystal
- Parameters
ax (plt.Axes) – matplotlib Axes object, must have projection=’3d’
pos (np.array) – array of atomic positions
kwargs (dict,optional) – keyword arguments passed to plt.plot
- Returns
a list of plt.Line3D
- Return type
list
-
qharv.inspect.crystal.
draw_cell
(ax, axes, corner=None, enclose=True, **kwargs)[source]¶ draw cell on ax see example in draw_crystal
- Parameters
ax (plt.Axes) – matplotlib Axes object, must have projection=’3d’
axes (np.array) – lattice vectors in row-major 3x3 array
corner (np.array,optional) – lower left corner of the lattice ,use (0,0,0) by default
enclose (bool) – enclose the cell with lattice vectors ,default is True. If False, then draw lattice vectors only
kwargs (dict,optional) – keyword arguments passed to plt.plot
- Returns
a list of plt.Line3D or Line, one for each lattice vector
- Return type
list
Example
>>> # draw 2D rectangular box, centered around (0, 0) >>> box = np.array([3.0, 1.5]) >>> axes = np.diag(box) >>> fig, ax = plt.subplots(1, 1) >>> lines = draw_cell(ax, axes, corner=-box/2) >>> plt.show()
-
qharv.inspect.crystal.
draw_crystal
(ax, axes, pos, draw_super=False)[source]¶ draw crystal structure on ax
Example
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D
axes = np.eye(3) pos = np.array([ [0.5,0.5,0.5] ])
fig = plt.figure() ax = fig.add_subplot(1,1,1,projection=’3d’) draw_crystal(ax,axes,pos) plt.show()
- Parameters
ax (plt.Axes) – matplotlib Axes object, must have projection=’3d’
axes (np.array) – lattice vectors in row-major 3x3 array
pos (np.array) – array of atomic positions
draw_super (bool) – draw 2x2x2 supercell
- Returns
- (cell, atoms) cell is a list of plt.Line3D for the cell,
atoms is a list of plt.Line3D for the atoms.
- Return type
(list, list)
-
qharv.inspect.crystal.
draw_dimers
(ax, com, bonds, **kwargs)[source]¶ draw dimers on ax
- Parameters
ax (plt.Axes) – matplotlib Axes object, must have projection=’3d’
com (np.array) – center of mass of dimers
bonds (np.array) – bond vectors of dimers
kwargs (dict,optional) – keyword arguments passed to plt.plot
- Returns
3 plot objects (monomer1, monomer2, bond)
- Return type
tuple
-
qharv.inspect.crystal.
draw_forces
(ax, pos, vel, **kwargs)[source]¶ draw forces on atoms
- Parameters
ax (plt.Axes) – matplotlib Axes object, must have projection=’3d’
pos (np.array) – array of atomic positions
vel (np.array) – array of forces on each atom (or velocities)
kwargs (dict,optional) – keyword arguments passed to plt.plot
- Returns
a list of plt.Line3D
- Return type
list
qharv.inspect.grsk module¶
-
qharv.inspect.grsk.
ase_gofr
(atoms, bin_edges, gr_norm)[source]¶ - Calculate the real-space pair correlation function g(r) among
all pairs of atom types. Histogram distances along the radial direction, i.e. spherically averaged.
- Parameters
atoms (ase.Atoms) – atoms
bin_edges (np.array) – histogram bin edges
gr_norm (np.array) – normalization of each bin
- Returns
gr1_map, one g(r) for each pair of atom types.
- Return type
dict
Example
>>> axes = np.eye(3) >>> pos = np.array([[0, 0, 0], [0.5, 0.5, 0.5]]) >>> atoms = Atoms('H2', cell=axes, positions=pos, pbc=1) >>> bin_edges = get_bin_edges(axes) >>> gr_norm = get_gofr_norm(axes, bin_edges, len(pos)) >>> gr1_map = ase_gofr(atoms, bin_edges, gr_norm) >>> gr1 = gr1_map[(0, 0)] >>> r = 0.5*(bin_edges[1:]+bin_edges[:-1]) >>> plt.plot(r, gr1) >>> plt.show()
qharv.inspect.inp_xml module¶
-
qharv.inspect.inp_xml.
check_psp_access
(doc, calc_dir)[source]¶ check that pseudopotential files can be accessed by input
- Parameters
doc (etree.Element) – must contain <hamiltonian>
- Returns
can access all pseudopotentials
- Return type
bool
-
qharv.inspect.inp_xml.
check_wf_hdf5
(snode, calc_dir, folded)[source]¶ check that spline single-particle orbitals are defined in the correct simulation cell. snode must hold the simulation cell and basis builder with a reference to the wf hdf5.
- Parameters
snode (lxml.Element) – e.g. parsed <qmcsystem>
calc_dir (str) – directory to contain the QMCPACK input
folded (bool) – True, if DFT was performed in unit cell and orbitals are tiled to super cell
- Returns
consistent
- Return type
bool
-
qharv.inspect.inp_xml.
check_wfh5_access
(doc, calc_dir)[source]¶ check that the Bspline h5 file can be accessed from input location
- Parameters
doc (etree.Element) – must containt <sposet_builder>
calc_dir (str) – directory to contain the QMCPACK input (doc)
- Returns
can access all h5 files
- Return type
bool
-
qharv.inspect.inp_xml.
validate_bspline_rcut
(node, ignore_empty=False)[source]¶ check that 1D bspline functions have valid cutoff radius
- Parameters
node (lxml.etree._Element) – xml node containing <simulationcell> and <correlation>.
ignore_empty (bool,optional) – ignore inputs without <correlation>, default=False
- Returns
valid input
- Return type
bool
qharv.inspect.jas module¶
-
qharv.inspect.jas.
bspline_on_rgrid
(doc, cid, rgrid=None, rcut=None, cusp=None)[source]¶ evaluate QMCPACK Basis spline on a real-space grid
doc must contain the desired Bspline <correlation> <coefficient> nodes <correlation size=”8” rcut=”4.0”>
<coefficient id=”cid” type=”Array”> 0.5 0.1 </coefficients>
</correlation>
- Parameters
doc (etree.Element) – must contain the Bspline component to read
cid (str) – coefficient name (id)
rgrid (list) – a list of radial grid values
rcut (float, optional) – cutoff radius, default is to read from
<correlation> –
cusp (float, optional) – cusp at r=0, default is to read from
<correlation> –
- Returns
a list of floats
- Return type
list
-
qharv.inspect.jas.
find_iopt
(iopt, opt_dir)[source]¶ locate opt.xml file in opt_dir :param iopt: optimization step (series id) :type iopt: int :param opt_dir: path to optimization run :type opt_dir: str
- Returns
floc, location of the requested opt.xml file
- Return type
str
-
qharv.inspect.jas.
get_coeff
(doc, coef_id)[source]¶ extract coefficients from a <coefficients> node
- Parameters
doc (etree.Element) – <coefficient> node
coef_id (str) – coefficient name (id), e.g. ‘uu’, ‘ud’, ‘cG2’
- Returns
extracted coefficients
- Return type
array-like
-
qharv.inspect.jas.
read_dat
(j2_dat)[source]¶ read the first two columns of a .dat file spewed out by QMCPACK
Examples
read_dat(‘J2.uu.dat’) read_dat(‘uk.g000.dat’) read_dat(‘BFe-e.ud.dat’)
- Parameters
j2_dat (str) – filename
- Returns
(r, v), first two columns, probably (radial grid, values)
- Return type
tuple
qharv.inspect.volumetric module¶
-
qharv.inspect.volumetric.
axes_func_on_grid3d
(axes, func, grid_shape)[source]¶ put a function define in axes units on a 3D grid :param axes: dtype=float, shape=(3,3);
3D lattice vectors in row major (i.e. a1 = axes[0])
- Parameters
func (RegularGridInterpolator) – 3D function defined on the unit cube
grid_shape (np.array) – dtype=int, shape=(3,); shape of real space grid
- Returns
dtype=float, shape=grid_shape; volumetric data
- Return type
grid (np.array)
-
qharv.inspect.volumetric.
color_scatter
(ax, xyz, vals=None, cmap_name='viridis', **kwargs)[source]¶ view sampled 3D scalar function using value as color
- Parameters
ax (plt.Axes3D) – ax = fig.add_subplot(1,1,1,projection=”3d”)
xyz (np.array) – a list of 3D vectors [(x1,y1,z1), (x2,y2,z2), …]
vals (np.array, optional) – f(x,y,z) one for each xyz vector, default is all ones
cmap_name (str, optional) – color map name, default is ‘viridis’
kwargs (dict, optional) – keyword arguments to be passed to ax.scatter
- Returns
scatter plot
- Return type
mpl_toolkits.mplot3d.art3d.Path3DCollection
-
qharv.inspect.volumetric.
figax3d
(show_axis=True, label_axis=True, **kwargs)[source]¶ get a pair of fig and Axes3D similar to subplots() but for a single 3D figure
- Parameters
show_axis (bool, optional) – show x, y, z axes and ticks, default True
- Returns
matplotlib.figure.Figure, matplotlib.axes._subplots.Axes3DSubplot
- Return type
tuple
-
qharv.inspect.volumetric.
isosurf
(ax, vol, level_frac=0.25)[source]¶ draw iso surface of volumetric data on matplotlib axis at given level
- Example usage:
from mpl_toolkits.mplot3d import Axes3D # enable 3D projection vol = np.random.randn(10,10,10) fig = plt.figure() ax = fig.add_subplot(1,1,1,projection=’3d’) isosurf(ax,vol) plt.show()
- Parameters
ax (plt.Axes3D) – ax = fig.add_subplot(1,1,1,projection=”3d”)
vol (np.array) – 3D volumetric data having shape (nx,ny,nz)
level_frac (float) – 0.0->1.0, isosurface value as a fraction between min and max
- Returns
mesh
- Return type
Poly3DCollection
- Effect:
draw on ax
-
qharv.inspect.volumetric.
read_gaussian_cube
(fcub)[source]¶ Read Gaussian cube file
Example
entry = read_gaussian_cube(‘density.cub’) data = np.array(entry[‘data’]) assert np.allclose(data.shape, entry[‘nxyz’])
- Parameters
fcub (str) – cube file name
- Returns
- dictionary of useful info
[axes, elem, pos, nxyz, data]
- Return type
dict
-
qharv.inspect.volumetric.
read_xsf_datagrid_3d_density
(fname, header='BEGIN_DATAGRID_3D_density', trailer='END_DATAGRID_3D_density')[source]¶ parse DATAGRID_3D block in xsf file
- Parameters
fname (str) – xsf file name
header (str) – tag marking the beginning of grid
trailer (str) – tag marking the end of grid
- Returns
data of 3D grid
- Return type
np.array
-
qharv.inspect.volumetric.
spline_volumetric
(val3d)[source]¶ spline 3D volumetric data onto a unit cube
- Parameters
val3d (np.array) – 3D volumetric data of shape (nx,ny,nz)
- Returns
3D function defined on the unit cube
- Return type
RegularGridInterpolator
-
qharv.inspect.volumetric.
write_gaussian_cube_text
(vol, axes, elem=(1, ), pos=((0, 0, 0), ), origin=(0, 0, 0), two_line_comment='cube\nfile\n')[source]¶ Write Gaussian cube file using volumetric data
- Parameters
vol (np.array) – volumetric data, shape (nx, ny, nz)
axes (np.array) – grid basis, e.g. np.diag((dx, dy, dz))
elem (array-like, optional) – list of atomic numbers, default (1,)
pos (array-like, optional) – list of atomic positions
origin (array-like, optional) – coordinates of the origin
two_line_comment (str, optional) – comments at file head
- Returns
Gaussian file content
- Return type
str
-
qharv.inspect.volumetric.
write_stanford_ply
(verts, faces)[source]¶ save polygons in ply format
ply is simpler than obj, but older and less used
- Parameters
verts (np.array) – shape=(nvert,3) dtype=float, vertices in cartesian coordinates.
faces (np.array) – shape=(nface,nside) dtype=int, polygons each specified as a list of vertices (in vertex coordinates defined by verts).
- Returns
content of the ply file
- Return type
str
-
qharv.inspect.volumetric.
write_wavefront_obj
(verts, faces, normals)[source]¶ save polygons in obj format
obj format is more commonly used than ply
- Parameters
verts (np.array) – shape=(nvert,3) dtype=float, vertices in cartesian coordinates.
faces (np.array) – shape=(nface,nside) dtype=int, polygons each specified as a list of vertices (in vertex coordinates defined by verts).
normals (np.array) – shape=(nvert,3) dtype=float, normal vectors used for smooth lighting. There is one normal vector per vertex.
- Returns
content of the obj file
- Return type
str