Skip to content

Commit

Permalink
debug site symmetry and 1d-rep function
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Apr 18, 2024
1 parent 7c1d092 commit 4749705
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 41 deletions.
57 changes: 34 additions & 23 deletions pyxtal/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,32 @@ def to_pyxtal(self):
raise ValueError("Problem in Lattice")

# sites
struc.numIons = [0] * len(smiles)
struc.numIons = []
struc.atom_sites = []

count = 1
for i, comp in enumerate(composition):
for j in range(comp):
v = self.x[count]
dicts = {}
dicts['type'] = i
dicts['dim'] = 3
dicts['PBC'] = [1, 1, 1]
dicts['hn'] = struc.group.hall_number
dicts['index'] = 0
dicts['lattice'] = struc.lattice.matrix
dicts['lattice_type'] = ltype
site = atom_site.from_1D_dicts(dicts)
site.type = i
struc.atom_sites.append(site)
struc.numIons[i] += site.wp.multiplicity
#move to next rep
count += 1
struc.species.append(site.specie)

species = []

for _x in self.x[1:]:
dicts = {}
specie, index, pos = _x[0], _x[1], _x[2:]
dicts['specie'] = specie
dicts['index'] = index
dicts['dim'] = 3
dicts['PBC'] = [1, 1, 1]
dicts['hn'] = struc.group.hall_number
wp = struc.group[index]
dicts['position'] = wp.get_position_from_free_xyzs(pos)
site = atom_site.load_dict(dicts)
struc.atom_sites.append(site)

if specie not in species:
species.append(specie)
struc.numIons.append(wp.multiplicity)
else:
for i, _specie in enumerate(species):
if _specie == specie:
struc.numIons[i] += site.wp.multiplicity

struc.species = species
struc._get_formula()
struc.source = '1D rep.'
struc.valid = True
Expand Down Expand Up @@ -150,7 +153,7 @@ def to_string(self, time=None, eng=None, tag=None):
strs += "{:s} ".format(x[i][0])
strs += "{:d} ".format(x[i][1])
for v in x[i][2:]:
strs += "{:4.2f} ".format(v)
strs += "{:6.4f} ".format(v)

if time is not None:
strs += "{:5.2f}".format(time)
Expand Down Expand Up @@ -506,6 +509,14 @@ def get_dist(self, rep):
print(string2)
print(rep4.get_dist(rep5))

from pyxtal import pyxtal
xtal = pyxtal()
xtal.from_seed('pyxtal/database/cifs/Fd3.cif')
xtal.from_seed('pyxtal/database/cifs/NaSb3F10.cif')
rep = representation_atom.from_pyxtal(xtal)
print(rep)
print(xtal)
print(rep.to_pyxtal())
#strings = [
#"83 14.08 6.36 25.31 83.9 1 0.72 0.40 0.27 131.6 -17.0 -120.0 -83.8 -134.1 -174.5 -175.7 -168.8 173.9 178.0 -157.4 0",
#"81 14.08 6.36 25.31 83.9 1 0.59 0.81 0.39 -117.8 -50.1 -95.3 -25.8 -80.6 164.7 155.9 -124.9 -159.2 178.6 -154.7 0",
Expand Down
41 changes: 23 additions & 18 deletions pyxtal/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2692,15 +2692,15 @@ class site_symmetry:
def __init__(self, ops, lattice_type, directions):

#self.G = G
opas = [OperationAnalyzer(op) for op in ops]
self.opas = [OperationAnalyzer(op) for op in ops]
self.directions = directions
self.lattice_type = lattice_type

rotations = []
for i in range(len(self.directions)): rotations.append({})
self.inversion = False

for opa in opas:
for opa in self.opas:
#print(opa.type, opa.order)
# Search for the primary rotation axis
if opa.type == "inversion":
Expand All @@ -2726,16 +2726,17 @@ def __init__(self, ops, lattice_type, directions):

if np.isclose(abs(np.dot(opa.axis, ax0)), 1):
store = True
break
# rotation axis
#print(store, 'update')
if store:
if ax in rotations[i].keys():
if opa.order >= rotations[i][ax][-1]:
#print('update ax', opa.order, opa.type, ax, i, symbol, self.inversion)
rotations[i][ax] = (symbol, opa.order)
else:
#print('add ax', opa.order, opa.type, ax, i, symbol, self.inversion)
if store:
if ax in rotations[i].keys():
if opa.order >= rotations[i][ax][-1]:
#print('update ax', opa.axis, opa.order, opa.type, ax, i, symbol, self.inversion, np.dot(opa.axis, ax0))
rotations[i][ax] = (symbol, opa.order)
else:
#print('add ax', opa.axis, opa.order, opa.type, ax, i, symbol, self.inversion, np.dot(opa.axis, ax0))
rotations[i][ax] = (symbol, opa.order)

self.get_symbols(rotations)
self.get_name()
Expand Down Expand Up @@ -2768,7 +2769,6 @@ def get_symbols(self, rotations):
self.symbols.append(symbol)

# Some simplifications
# 2/m => m for higher than mmm
if self.lattice_type == 'orthorhombic':
if self.symbols == ['2/m', '2/m', '2/m']:
self.symbols = ['m', 'm', 'm']
Expand All @@ -2781,6 +2781,8 @@ def get_symbols(self, rotations):
self.symbols[i+1] = 'm'
if self.symbols == ['4/m', '2/m', '2/m']:
self.symbols = ['4/mmm']
elif self.symbols == ['2/m', '2/m', '.']:
self.symbols = ['m', 'mm', '.']

elif self.lattice_type in ['trigonal', 'hexagonal']:
for i, symbol in enumerate(self.symbols):
Expand All @@ -2795,7 +2797,7 @@ def get_symbols(self, rotations):
for i, symbol in enumerate(self.symbols):
#if symbol in ['22', '222', '222222']:
# if 222 appears alone, don't symplify
if symbol in ['22', '2222', '222222']:
if symbol in ['2222', '222222']:
self.symbols[i] = '2'
elif symbol in ['333', '3333']:
self.symbols[i] = '3'
Expand All @@ -2815,9 +2817,16 @@ def get_symbols(self, rotations):
self.symbols[i] = 'mm2'
elif symbol in ['2m']:
self.symbols[i] = 'm2'
elif symbol in ['4mm']:
self.symbols[i] = '4m'

if self.symbols in [['4', '-3', '2'], ['-4', '-3', 'm']]:
self.symbols = ['m', '-3', 'm']

if '222' in self.symbols:
if len(self.opas) > 4:
for i in range(len(self.symbols)):
if self.symbols[i] == '222':
self.symbols[i] = '2'#; print('Find ===')
def get_name(self):
if self.symbols in [['.', '.', '.'], ['.', '.'], ['.']]:
if self.inversion:
Expand All @@ -2830,6 +2839,7 @@ def get_name(self):
self.name += symbol



def organized_wyckoffs(group):
"""
Takes a Group object or unorganized list of Wyckoff positions and returns
Expand Down Expand Up @@ -3749,7 +3759,7 @@ def get_symmetry_directions(lattice_type, symbol='P', unique_axis='b'):
if __name__ == "__main__":
print("Test of pyxtal.symmetry")
#for i in range(1, 231):
for i in [143, 160, 230]:
for i in [225, 227, 230]:#93, 123]: #143, 160, 230]:
g = Group(i)
print(g.lattice_type, g.symbol)
for wp in g:
Expand All @@ -3760,8 +3770,3 @@ def get_symmetry_directions(lattice_type, symbol='P', unique_axis='b'):
ops = wp.symmetry[0]
ss = site_symmetry(ops, g.lattice_type, g.get_symmetry_directions())
print(wp.number, wp.multiplicity, wp.letter, ss.symbols, ss.name)
#op = SymmOp.from_xyz_str('y+1/8, -y+1/8, 0')
#op = SymmOp.from_xyz_str('1/8, y+1/8, -y+1/8')
#op = SymmOp.from_xyz_str(['x+1/8,x+1/8,z+1/8', '')
#print(trim_op(op).as_xyz_str())
#from_symops(ops, group=None, permutation=True)

0 comments on commit 4749705

Please sign in to comment.