Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]
# TODO: Add check for lattice symmetry
# Apply SymmOps to generate new points
# old_coords = filtered_coords(struct.frac_coords,PBC=PBC)
new_coords = []
new_species = []
for i, point in enumerate(old_coords):
for j, op in enumerate(generators):
if j != 0:
new_coords.append(op.operate(point))
new_species.append(old_species[i])
# new_coords = filtered_coords(new_coords,PBC=PBC)
wp = Wyckoff_position.from_group_and_index(20, 1)
except Exception as e:
fail(e)
check()
print(" Group")
try:
from pyxtal.symmetry import Group
except Exception as e:
fail(e)
if passed():
try:
g3 = Group(230)
g2 = Group(80, dim=2)
g1 = Group(75, dim=1)
except Exception as e:
fail(e)
check()
# =====crystal=====
print("pyxtal.crystal")
reset()
try:
import pyxtal.crystal
except Exception as e:
fail(e)
print(" random_crystal")
try:
def test_atomic_2D():
global outstructs
global outstrings
print("=== Testing generation of atomic 2D crystals. This may take some time. ===")
from time import time
from pyxtal.symmetry import Group
from pyxtal.crystal import random_crystal_2D
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
slow = []
failed = []
print(" Layer group # | Symbol | Time Elapsed")
skip = []
for sg in range(1, 81):
if sg not in skip:
g = Group(sg, dim=2)
multiplicity = len(g[0]) # multiplicity of the general position
start = time()
rand_crystal = random_crystal_2D(sg, ["C"], [multiplicity], 4.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 += "~"
if timespent >= 60.0:
t += " ~"
if timespent >= 3.0:
t += "~"
if timespent >= 10.0:
t += "~"
if timespent >= 60.0:
t += "~"
slow.append(sg)
if rand_crystal.valid:
if check_struct_group(rand_crystal, sg, dim=0):
pass
else:
t += " xxxxx"
outstructs.append(rand_crystal.struct)
outstrings.append(str("Cluster_" + str(sg) + ".vasp"))
pgsymbol = Group(sg, dim=0).symbol
print("\t" + str(sg) + "\t|\t" + pgsymbol + "\t|\t" + t)
else:
print(
"~~~~ Error: Could not generate space group "
+ str(sg)
+ " after "
+ t
)
failed.append(sg)
if slow != []:
print("~~~~ The following space groups took more than 60 seconds to generate:")
for i in slow:
print(" " + str(i))
if failed != []:
print("~~~~ The following space groups failed to generate:")
for i in failed:
try:
wp = Wyckoff_position.from_group_and_index(20, 1)
except Exception as e:
fail(e)
check()
print(" Group")
try:
from pyxtal.symmetry import Group
except Exception as e:
fail(e)
if passed():
try:
g3 = Group(230)
g2 = Group(80, dim=2)
g1 = Group(75, dim=1)
except Exception as e:
fail(e)
check()
# =====crystal=====
print("pyxtal.crystal")
reset()
try:
import pyxtal.crystal
except Exception as e:
fail(e)
print(" random_crystal")
# Check that numIons are integers greater than 0
for num in numIons:
if int(num) != num or num < 1:
printx(
"Error: stoichiometry must consist of positive integers.", priority=1,
)
return False
if type(group) == Group:
"""
A pyxtal.symmetry.Group object storing information
about the space/layer/Rod/point group,
and its Wyckoff positions.
"""
self.group = group
else:
self.group = Group(group, dim=self.dim)
self.number = self.group.number
"""
The international group number of the crystal:
1-230 for 3D space groups
1-80 for 2D layer groups
1-75 for 1D Rod groups
1-32 for crystallographic point groups
None otherwise
"""
# The number of attempts to generate the crystal, max1*max2*max3.
# number of atoms
# volume factor for the unit cell.
# The number of atom in the PRIMITIVE cell
# The number of each type of atom in the CONVENTIONAL cell.
# A list of atomic symbols for the types of atoms
select_high=True,
allow_inversion=False,
orientations=None,
check_atomic_distances=True,
fmt="xyz",
lattice=None,
tm=Tol_matrix(prototype="molecular"),
):
self.dim = 3
"""The number of periodic dimensions of the crystal"""
# Necessary input
self.PBC = [1, 1, 1]
"""The periodic axes of the crystal"""
if type(group) != Group:
group = Group(group, self.dim)
self.sg = group.number
self.selec_high = select_high
self.init_common(
molecules,
numMols,
volume_factor,
select_high,
allow_inversion,
orientations,
check_atomic_distances,
group,
lattice,
tm,
)
numMols,
volume_factor,
select_high=True,
allow_inversion=True,
orientations=None,
check_atomic_distances=True,
fmt="xyz",
thickness=None,
lattice=None,
tm=Tol_matrix(prototype="molecular"),
):
self.dim = 2
self.numattempts = 0
if type(group) != Group:
group = Group(group, self.dim)
number = group.number # The layer group number of the crystal."""
self.thickness = thickness # the thickness in Angstroms
self.PBC = [1, 1, 0]
self.init_common(
molecules,
numMols,
volume_factor,
select_high,
allow_inversion,
orientations,
check_atomic_distances,
group,
lattice,
tm,
)
check_atomic_distances,
group,
lattice,
tm,
):
"""
init functionality which is shared by 3D, 2D, and 1D crystals
"""
self.numattempts = 0
"""The number of attempts needed to generate the crystal."""
if type(group) == Group:
self.group = group
"""A pyxtal.symmetry.Group object storing information about the space/layer
/Rod/point group, and its Wyckoff positions."""
else:
self.group = Group(group, dim=self.dim)
self.number = self.group.number
"""The international group number of the crystal:
1-230 for 3D space groups
1-80 for 2D layer groups
1-75 for 1D Rod groups
1-32 for crystallographic point groups
None otherwise
"""
self.Msgs()
self.factor = volume_factor # volume factor for the unit cell.
numMols = np.array(numMols) # must convert it to np.array
self.numMols0 = numMols # in the PRIMITIVE cell
self.numMols = self.numMols0 * cellsize(self.group) # in the CONVENTIONAL cell
# boolean numbers
self.check_atomic_distances = check_atomic_distances
def init_common(self, species, numIons, factor, group, lattice, sites, tm):
"""
Common init functionality for 0D-3D cases of random_crystal.
"""
self.valid = False
# Check that numIons are integers greater than 0
for num in numIons:
if int(num) != num or num < 1:
printx(
"Error: stoichiometry must consist of positive integers.", priority=1,
)
return False
if type(group) == Group:
"""
A pyxtal.symmetry.Group object storing information
about the space/layer/Rod/point group,
and its Wyckoff positions.
"""
self.group = group
else:
self.group = Group(group, dim=self.dim)
self.number = self.group.number
"""
The international group number of the crystal:
1-230 for 3D space groups
1-80 for 2D layer groups
1-75 for 1D Rod groups
1-32 for crystallographic point groups
None otherwise