util
thmd.util
¶
Modules:
-
check_installation
– -
compute_angle
– -
compute_distance
– -
compute_tensor
– -
detect_sign_change
– -
grid_box
– -
many_stuff
– -
row_operation
– -
string_index
– -
unit
–This module to convert unit of some physical properties
check_installation
¶
Functions:
compute_angle
¶
Functions:
-
angle_vector2vectors
–copmute angles between a vector with set of vectors
angle_vector2vectors(fixVector, arrayVectors, unit='rad')
¶
copmute angles between a vector with set of vectors
compute_distance
¶
Functions:
-
dist2_point2points
–Compute bond_len and postion_vetors from 1 point to a list of points
-
dist2_points2line
–Compute bond_len and postion_vetors from 1 point to a list of points
-
closest_points2line
–Find all points locate inside a checkin-distance "dist" from a line.
-
closest_points2multilines
–Find all points locate inside a checkin-distance "dist" from multilines.
dist2_point2points(point, points)
¶
Compute bond_len and postion_vetors from 1 point to a list of points
Parameters:
-
point
(list array
) –coordinate of 1 point.
-
points
(list array
) –2d-list of coordinates of points/point.
Returns:
-
df
(DataFrame
) –pd.DataFrame constains distance and component of connecting vectors.
dist2_points2line(points, line=[(0, 0, 0), (0, 0, 0)])
¶
Compute bond_len and postion_vetors from 1 point to a list of points Ref: https://stackoverflow.com/questions/39840030/distance-between-point-and-a-line-from-two-points
Parameters:
-
points
(list array DataFrame
) –list of coordinates of points/point.
-
line
(list array
, default:[(0, 0, 0), (0, 0, 0)]
) –2d-array contains coordinates to define a line.
Returns:
-
d
(float list
) –distances between points and a line.
closest_points2line(points, line=[(0, 0, 0), (0, 0, 0)], distance=0, Xbound=None, Ybound=None, Zbound=None)
¶
Find all points locate inside a checkin-distance "dist" from a line.
Parameters:
-
points
(list array
) –list of coordinates of points/point.
-
line
(list array
, default:[(0, 0, 0), (0, 0, 0)]
) –[[x1,y1,z1], [x1,y2,z2]]: 2d-list contains coordinates to define a line.
-
distance
(float
, default:0
) –the checkin-distance.
-
Xbound
(tuple
, default:None
) –define the boundaries for checking. Xbound='line': use the lengths of lines as bounds. Xbound=None: extend to INF. Xbound = (xlo, xhi)
-
Ybound
(tuple
, default:None
) –define the boundaries for checking.
-
Zbound
(tuple
, default:None
) –define the boundaries for checking.
Returns:
-
ds_idx
(Series
) –Series of indices of points within the checkin-distance
closest_points2multilines(points, multilines=[], distance=0, Xbound=None, Ybound=None, Zbound=None)
¶
Find all points locate inside a checkin-distance "dist" from multilines. The Bound is set as the line-lengths.
Parameters:
-
points
(list array
) –list of coordinates of points/point.
-
multilines
(list
, default:[]
) –list of pair-points, each pair-point contains coordinates of 2 points to define a line used in 'closest_points2line'.
-
distance
(float
, default:0
) –the checkin-distance.
Returns:
-
ds_idx
(Series
) –Series of indices of points within the checkin-distance
compute_tensor
¶
Functions:
-
ke_tensor
–Compute Kinetic Energy tensors, and Temp
-
stress_tensor
–Compute local pressure/stress
ke_tensor(vel, mass, kb)
¶
Compute Kinetic Energy tensors, and Temp Args: vel (array): Nx3 array of per-atom velocity mass (array): Nx3 array of atomic mass inUNIT (str): ['angstrom','ps','amu','eV'], outUNIT=['eV','K'] Returns: Kinetic energy tensor, Kinetic scalar, Temperature scalar
stress_tensor(per_atom_stress_tensor, atomic_volume, unitFac=1)
¶
Compute local pressure/stress Args: per_atom_stress_tensor : Nx6 array of the per-atom stress tensor atomVol : Nx1 vector of atomVol inUNIT=['bar','angstrom'], outUNIT=['bar'] → unitFac=1e-4 for ['GPa'] Returns: pressure scalar Stress tensor
detect_sign_change
¶
Functions:
-
detect_sign_change
–determine points where line y=y(x) change its sign
detect_sign_change(y, x=[])
¶
determine points where line y=y(x) change its sign
Parameters:
-
y
–Nx1 arrays, contains dependent variable y
-
x
–(Optinal) Nx1 arrays, contains independent variable x of line y(x)
Returns:
-
idx
–1d array of indices where sign changes
grid_box
¶
Functions:
-
grid_box_2d
–devide box into 2d grid, return list of atom-IDs in each slab and list of slab-centers
-
grid_box_1d
–devide box into 1d slabs, return list of atom-IDs in each slab and list of slab-centers
grid_box_2d(points, box, plane='XY', mode='bin_number', grid_size=[20, 20])
¶
devide box into 2d grid, return list of atom-IDs in each slab and list of slab-centers Args: P : Nx3 array contain positions of atoms box : simulation box mode : "bin_number" or "bin_size" mode_value : corresponding 'Number-of-bins' or 'size-of-bin' plane : on which plane the box will be gridded Returns: atomIDinCell : 1xBinNumber array of 1xM-vector, contain indices of atoms of each Cell cellCenter : 1xBinNumber array of scalar, is center of each slab
grid_box_1d(points, box, axis='Z', mode='bin_number', grid_size=20)
¶
devide box into 1d slabs, return list of atom-IDs in each slab and list of slab-centers Args: P : Nx3 array contain positions of atoms box : simulation box mode : "bin_number" or "bin_size" mode_value : corresponding 'Number-of-bins' or 'size-of-bin' axis : on which axis the box will be slabbed Returns: atomIDinCell : 1xBinNumber array of 1xM arrays, contain indices of atoms of each Slab, array of arrays geoCenter : 1xBinNumber array of scalar, is geometry center of each slab massCenter : 1xBinNumber array of scalar, is mass center of each slab
many_stuff
¶
Functions:
-
memory_usage
–return the memory usage in MB
-
natSorted
– -
split_list
–Should use
np.array_split
instead -
find_nearest_value
–
row_operation
¶
Functions:
-
unique_row
–find match_indices & mismatch_indices of arr(find_rows) in arr(X), return indices of X
-
match_row
–find match_indices & mismatch_indices of arr(find_rows) in arr(X), return indices of X
-
asvoid
–
unique_row(X, tol_decimal=2)
¶
find match_indices & mismatch_indices of arr(find_rows) in arr(X), return indices of X Args: X, find_rows : NxN numpy arrays tol_decimal : number of digits for round off input data
match_row(X, find_rows, tol_decimal=2)
¶
find match_indices & mismatch_indices of arr(find_rows) in arr(X), return indices of X Args: X, find_rows : NxN numpy arrays tol_decimal : number of digits for round off input data
string_index
¶
Functions:
-
string_index
–groupSURF index by consecutive-series
string_index(idx_list)
¶
groupSURF index by consecutive-series
unit
¶
This module to convert unit of some physical properties pressure
Consider to use this module: https://unyt.readthedocs.io/en/stable/usage.html
Functions:
-
pressure
–convert unit of pressure
-
force
–convert unit of force
-
energy
–convert unit of energy
-
constant
–list of constants
pressure(key_word='all_key')
¶
convert unit of pressure Pa: Pascal atm: standard atmosphere at: technical atmosphere
kgf/cm2 = kg/cm2 1 Pa = 1 N/m^2 1 kgf/cm2 = 1
Parameters:
-
key_word
(str
, default:'all_key'
) –a string to specify units to be converted.
Returns:
-
factor
(float
) –multiply factor of conversion
Examples:
force(key_word='all_key')
¶
convert unit of force N: Newton kgf = m.g: kilogram-force (weight: one kilogram of mass in a 9.80665 m/s2 gravitational field) lbf: pound-force p: pond
1 N = 1 J/m (Work = Force.distance) 1 kcal = 4184 J = 4184 N.m = 4184.10^10 N.Angstrom 69.4786 pN = 1 kcal/mol Angstrom. https://tinyurl.com/yb2gnlhc
Parameters:
-
key_word
(str
, default:'all_key'
) –a string to specify units to be converted.
Returns:
-
factor
(float
) –multiply factor of conversion
energy(key_word='all_key')
¶
convert unit of energy J: Joule W.h: watt-hour cal: calorie (th) hp.h: horsepower hour eV: electron-volt
1 J = 1 N.m (Work = Force.distance) 1J = 1 W.s
Parameters:
-
key_word
(str
, default:'all_key'
) –a string to specify units to be converted.
Returns:
-
factor
(float
) –multiply factor of conversion
Notes
constant(key_word='all_key')
¶
list of constants Na = 6.02214076e23 (=1/mol): Avogadro number
Parameters:
-
Ex
–key_word='Pa_atm': convert from Pa (Pascal) to atm (Standard atmosphere)
Returns: factor: float, multiply factor of conversion