Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def filter_zeroes(op):
m = op.affine_matrix
m2 = m
for i, x in enumerate(m):
for j, y in enumerate(x):
if np.isclose(y, 0, atol=1e-3):
m2[i][j] = 0
return SymmOp(m2)
layer_df = read_csv(resource_filename("pyxtal", "database/layer.csv"))
layer_symmetry_df = read_csv(resource_filename("pyxtal", "database/layer_symmetry.csv"))
layer_generators_df = read_csv(
resource_filename("pyxtal", "database/layer_generators.csv")
)
rod_df = read_csv(resource_filename("pyxtal", "database/rod.csv"))
rod_symmetry_df = read_csv(resource_filename("pyxtal", "database/rod_symmetry.csv"))
rod_generators_df = read_csv(resource_filename("pyxtal", "database/rod_generators.csv"))
point_df = read_csv(resource_filename("pyxtal", "database/point.csv"))
point_symmetry_df = read_csv(resource_filename("pyxtal", "database/point_symmetry.csv"))
point_generators_df = read_csv(
resource_filename("pyxtal", "database/point_generators.csv")
)
symbols = loadfn(resource_filename("pyxtal", "database/symbols.json"))
Identity = SymmOp.from_xyz_string("x,y,z")
Inversion = SymmOp.from_xyz_string("-x,-y,-z")
op_o = SymmOp.from_xyz_string("0,0,0")
op_x = SymmOp.from_xyz_string("x,0,0")
op_y = SymmOp.from_xyz_string("0,y,0")
op_z = SymmOp.from_xyz_string("0,0,z")
pglist = [
"C1",
"Ci",
"C2",
"Cs",
"C2h",
"D2",
"C2v",
"D2h",
"C4",
# Any molecule with infinitesimal symmetry is linear;
# Thus, it possess mirror symmetry for any axis perpendicular
# To the rotational axis. pymatgen does not add this symmetry
# for all linear molecules - for example, hydrogen
if axis == [1, 0, 0]:
symm_m.append(SymmOp.from_xyz_string("x,-y,z"))
symm_m.append(SymmOp.from_xyz_string("x,y,-z"))
r = SymmOp.from_xyz_string("-x,y,-z")
elif axis == [0, 1, 0]:
symm_m.append(SymmOp.from_xyz_string("-x,y,z"))
symm_m.append(SymmOp.from_xyz_string("x,y,-z"))
r = SymmOp.from_xyz_string("-x,-y,z")
elif axis == [0, 0, 1]:
symm_m.append(SymmOp.from_xyz_string("-x,y,z"))
symm_m.append(SymmOp.from_xyz_string("x,-y,z"))
r = SymmOp.from_xyz_string("x,-y,-z")
# Generate a full list of SymmOps for the molecule's pointgroup
symm_m = generate_full_symmops(symm_m, 1e-3)
break
# Reorient the SymmOps into mol's original frame
if not already_oriented:
new = []
for op in symm_m:
new.append(P.inverse * op * P)
return new
elif already_oriented:
return symm_m
# Handle nonlinear molecules
else:
pg = pga.get_pointgroup()
symm_m = []
for op in pg:
if m[0][0] != 1:
x_factor = m[0][0]
if m[1][1] != 0:
if m[1][1] != 1:
y_factor = m[1][1]
if m[2][2] != 0:
if m[2][2] != 1:
z_factor = m[2][2]
new_list = []
for op in op_list:
m = op.affine_matrix
m2 = m
m2[:, 0] = m2[:, 0] / x_factor
m2[:, 1] = m2[:, 1] / y_factor
m2[:, 2] = m2[:, 2] / z_factor
new_list.append(SymmOp(m2))
return new_list
num: the Rod group number
molecular: whether or not to convert to Euclidean reference frame
(for hexagonal lattices: point groups 16-27)
Returns:
a 2d list of SymmOp objects which can be used to generate a Wyckoff position given a
single fractional (x,y,z) coordinate
"""
generator_strings = eval(point_generators_df["0"][num])
generators = []
# Loop over Wyckoff positions
for x in generator_strings:
generators.append([])
# Loop over ops
for y in x:
op = SymmOp(y)
generators[-1].append(op)
return generators
Args:
angle: an angle to rotate about the constraint axis. If "random",
chooses a random rotation angle. If self.degrees==2, chooses a
random 3d rotation matrix to multiply by. If the original matrix
is wanted, set angle=0, or call self.matrix
Returns:
pymatgen.core.structure. SymmOp object
"""
# If "random", rotates by a random amount
if angle is not None:
self.change_orientation(angle)
return SymmOp.from_rotation_and_translation(self.matrix, [0, 0, 0])
if len(axis) != 3:
return
# Vector must be non-zero
if axis.dot(axis) < 1e-6:
return
v = np.array(axis) / np.linalg.norm(axis)
# Find largest component (x, y, or z)
abs_vals = [abs(a) for a in v]
f1 = max(abs_vals)
index1 = list(abs_vals).index(f1)
# Initialize an affine matrix
m = np.eye(4)
m[:3] = [0.0, 0.0, 0.0, 0.0]
# Set values for affine matrix
m[:3, index1] = v
return SymmOp(m)
generate = True
# interpret symbol
if symbol[0] == "I":
# Icosohedral
self.lattice_type = "spherical"
# Add 2, 3, and 5-fold rotations
gens.append(SymmOp.from_xyz_string("-x,-y,z"))
gens.append(SymmOp.from_xyz_string("z,x,y"))
tau = 0.5 * (np.sqrt(5) + 1)
m = aa2matrix([1.0, tau, 0.0], 2 * np.pi / 5)
gens.append(SymmOp.from_rotation_and_translation(m, [0, 0, 0]))
# Add Wyckoff generating operations
op_c = SymmOp.from_xyz_string("x,0,0")
op_b = SymmOp.from_xyz_string("x,x,x")
m = [[0, 0, 0, 0], [0, 1, 0, 0], [0, tau, 0, 0], [0, 0, 0, 0]]
op_a = SymmOp(m)
gen_ops = [Identity, op_c, op_b, op_a, op_o]
if symbol == "Ih":
# Add horizontal mirror plane
mirror = SymmOp.from_xyz_string("x,y,-z") # m x,y,0
gens.append(mirror)
op_d = SymmOp.from_xyz_string("0,y,z")
gen_ops = [Identity, op_d, op_c, op_b, op_a, op_o]
elif symbol[0] == "C" and symbol[-1] != "i":
# n-fold rotation
if num == 1:
self.lattice_type = "spherical"
else:
self.lattice_type = "ellipsoidal"
op_b = SymmOp.from_xyz_string("0,y,z")
op_c = SymmOp.from_xyz_string("x,0,z")
elif molecular is True:
op = SymmOp.from_rotation_and_translation(
op.rotation_matrix, [0, 0, 0]
)
generators[-1].append(op)
else:
generators.append([])
for y in x:
op = SymmOp.from_xyz_string(y)
if convert is True:
# Convert non-orthogonal trigonal/hexagonal operations
op = P * op * P.inverse
if molecular is False:
generators[-1].append(op)
elif molecular is True:
op = SymmOp.from_rotation_and_translation(
op.rotation_matrix, [0, 0, 0]
)
generators[-1].append(op)
return generators
Args:
num: the point group number (see bottom of source code for a list)
organized: whether or not to organize the list based on multiplicity
molecular: whether or not to convert to Euclidean reference frame
(for hexagonal lattices: point groups 16-27)
Returns:
a list of Wyckoff positions, each of which is a list of SymmOp's
"""
wyckoff_strings = eval(point_df["0"][num])
wyckoffs = []
for x in wyckoff_strings:
wyckoffs.append([])
for y in x:
op = SymmOp(y)
wyckoffs[-1].append(op)
if organized:
wyckoffs_organized = [[]] # 2D Array of WP's organized by multiplicity
old = len(wyckoffs[0])
for wp in wyckoffs:
mult = len(wp)
if mult != old:
wyckoffs_organized.append([])
old = mult
wyckoffs_organized[-1].append(wp)
return wyckoffs_organized
else:
return wyckoffs