Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
position, and makes sure at least one valid combination of WP's exists.
"""
# Store whether or not at least one degree of freedom exists
has_freedom = False
# Store the wp's already used that don't have any freedom
used_indices = []
# Loop over species
for i_mol, numIon in enumerate(numMols):
# Get lists of multiplicity, maxn and freedom
l_mult0 = []
l_maxn0 = []
l_free0 = []
indices0 = []
for i_wp, wp in enumerate(group):
# Check that at least one valid orientation exists
j, k = jk_from_i(i_wp, group.wyckoffs_organized)
if len(valid_orientations[i_mol][j][k]) > 0:
indices0.append(i_wp)
l_mult0.append(len(wp))
l_maxn0.append(numIon // len(wp))
if np.allclose(wp[0].rotation_matrix, np.zeros([3, 3])):
l_free0.append(False)
else:
l_free0.append(True)
# Remove redundant multiplicities:
l_mult = []
l_maxn = []
l_free = []
indices = []
for mult, maxn, free, i_wp in zip(l_mult0, l_maxn0, l_free0, indices0):
if free is True:
if mult not in l_mult:
try:
import pyxtal.symmetry
except Exception as e:
fail(e)
print(" get_wyckoffs (may take a moment)")
try:
from pyxtal.symmetry import get_wyckoffs
except Exception as e:
fail(e)
if passed():
try:
for i in [1, 2, 229, 230]:
get_wyckoffs(i)
get_wyckoffs(i, organized=True)
except:
fail(" Could not access Wyckoff positions for space group # " + str(i))
check()
print(" get_wyckoff_symmetry (may take a moment)")
try:
from pyxtal.symmetry import get_wyckoff_symmetry
except Exception as e:
fail(e)
if passed():
try:
for i in [1, 2, 229, 230]:
get_wyckoff_symmetry(i)
get_wyckoff_symmetry(i, molecular=True)
else:
lattice = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
old_coords = np.array(crystal)
old_species = ["C"] * len(old_coords)
from pyxtal.symmetry import distance
from pyxtal.symmetry import filtered_coords
from copy import deepcopy
PBC = [1, 1, 1]
# Obtain the generators for the group
if dim == 3:
from pyxtal.symmetry import get_wyckoffs
generators = get_wyckoffs(group)[0]
elif dim == 2:
from pyxtal.symmetry import get_layer
generators = get_layer(group)[0]
PBC = [1, 1, 0]
elif dim == 1:
from pyxtal.symmetry import get_rod
generators = get_rod(group)[0]
PBC = [0, 0, 1]
elif dim == 0:
from pyxtal.symmetry import Group
generators = Group(group, dim=0)[0]
PBC = [0, 0, 0]
except Exception as e:
fail(e)
check()
print(" ss_string_from_ops")
try:
from pyxtal.symmetry import ss_string_from_ops
except Exception as e:
fail(e)
if passed():
try:
strings = ["1", "4 . .", "2 3 ."]
for i, sg in enumerate([1, 75, 195]):
ops = get_wyckoffs(sg)[0]
ss_string_from_ops(ops, sg, dim=3)
except Exception as e:
fail(e)
check()
print(" Wyckoff_position")
try:
from pyxtal.symmetry import Wyckoff_position
except Exception as e:
fail(e)
if passed():
try:
wp = Wyckoff_position.from_group_and_index(20, 1)
except Exception as e:
reset()
try:
import pyxtal.symmetry
except Exception as e:
fail(e)
print(" get_wyckoffs (may take a moment)")
try:
from pyxtal.symmetry import get_wyckoffs
except Exception as e:
fail(e)
if passed():
try:
for i in [1, 2, 229, 230]:
get_wyckoffs(i)
get_wyckoffs(i, organized=True)
except:
fail(" Could not access Wyckoff positions for space group # " + str(i))
check()
print(" get_wyckoff_symmetry (may take a moment)")
try:
from pyxtal.symmetry import get_wyckoff_symmetry
except Exception as e:
fail(e)
if passed():
try:
for i in [1, 2, 229, 230]:
get_wyckoff_symmetry(i)
from time import time
from spglib import get_symmetry_dataset
from pyxtal.symmetry import get_wyckoffs
from pyxtal.crystal import random_crystal
from pyxtal.crystal import cellsize
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
slow = []
failed = []
print(" Spacegroup # |Generated (SPG)|Generated (PMG)| Time Elapsed")
skip = (
[]
) # [124, 139, 166, 167, 196, 202, 203, 204, 207, 209, 210, 216, 217, 219, 220, 221, 223, 225, 226, 227, 228, 229, 230] #slow to generate
for sg in range(1, 231):
if sg not in skip:
multiplicity = len(get_wyckoffs(sg)[0]) / cellsize(
sg
) # multiplicity of the general position
start = time()
rand_crystal = random_crystal(sg, ["C"], [multiplicity], 1.0)
end = time()
timespent = np.around((end - start), decimals=2)
t = str(timespent)
if len(t) == 3:
t += "0"
t += " s"
if timespent >= 1.0:
t += " ~"
if timespent >= 3.0:
t += "~"
if timespent >= 10.0:
t += "~"
else:
fail()
except Exception as e:
fail(e)
check()
print(" index_from_letter")
try:
from pyxtal.symmetry import index_from_letter
except Exception as e:
fail(e)
if passed():
try:
if index_from_letter("A", get_wyckoffs(47)) == 0:
pass
else:
fail()
except Exception as e:
fail(e)
check()
print(" jk_from_i")
try:
from pyxtal.symmetry import jk_from_i
except Exception as e:
fail(e)
if passed():
try:
def compare_wyckoffs(num1, num2, dim=3):
"""Given 2 groups, return whether the second point
group has equal or greater symmetry than the first group."""
from numpy import allclose
if num1 == "???":
print("Error: invalid value for num1 passed to compare_wyckoffs")
return
if num2 == "???":
return False
# Get general positions for both groups
if dim == 3:
from pyxtal.symmetry import get_wyckoffs
g1 = get_wyckoffs(num1)[0]
g2 = get_wyckoffs(num2)[0]
elif dim == 2:
from pyxtal.symmetry import get_layer
g1 = get_layer(num1)[0]
g2 = get_layer(num2)[0]
elif dim == 1:
from pyxtal.symmetry import get_rod
g1 = get_rod(num1)[0]
g2 = get_rod(num2)[0]
elif dim == 0:
from pyxtal.symmetry import get_point
g1 = get_point(num1)[0]
g2 = get_point(num2)[0]
# If group 2 has higher symmetry
def compare_wyckoffs(num1, num2, dim=3):
"""Given 2 groups, return whether the second point
group has equal or greater symmetry than the first group."""
from numpy import allclose
if num1 == "???":
print("Error: invalid value for num1 passed to compare_wyckoffs")
return
if num2 == "???":
return False
# Get general positions for both groups
if dim == 3:
from pyxtal.symmetry import get_wyckoffs
g1 = get_wyckoffs(num1)[0]
g2 = get_wyckoffs(num2)[0]
elif dim == 2:
from pyxtal.symmetry import get_layer
g1 = get_layer(num1)[0]
g2 = get_layer(num2)[0]
elif dim == 1:
from pyxtal.symmetry import get_rod
g1 = get_rod(num1)[0]
g2 = get_rod(num2)[0]
elif dim == 0:
from pyxtal.symmetry import get_point
g1 = get_point(num1)[0]
g2 = get_point(num2)[0]
for i in [1, 2, 229, 230]:
get_wyckoff_generators(i)
except:
fail("Could not access Wyckoff generators for space group # " + str(i))
check()
print(" letter_from_index")
try:
from pyxtal.symmetry import letter_from_index
except Exception as e:
fail(e)
if passed():
try:
if letter_from_index(0, get_wyckoffs(47)) == "A":
pass
else:
fail()
except Exception as e:
fail(e)
check()
print(" index_from_letter")
try:
from pyxtal.symmetry import index_from_letter
except Exception as e:
fail(e)
if passed():
try: