mirror of https://github.com/phonopy/phonopy.git
A test for Symmetry class is added.
This commit is contained in:
parent
9bd28af1ef
commit
9dc26f7546
|
@ -69,13 +69,17 @@ class PhonopyYaml:
|
||||||
self._supercell_matrix = None
|
self._supercell_matrix = None
|
||||||
self._primitive_matrix = None
|
self._primitive_matrix = None
|
||||||
self._force_constants = None
|
self._force_constants = None
|
||||||
self._p2s_map = None
|
|
||||||
self._s2p_map = None
|
self._s2p_map = None
|
||||||
self._p2p_map = None
|
self._u2p_map = None
|
||||||
|
self._nac_params = None
|
||||||
|
self._version = None
|
||||||
|
|
||||||
def get_unitcell(self):
|
def get_unitcell(self):
|
||||||
return self._unitcell
|
return self._unitcell
|
||||||
|
|
||||||
|
def set_unitcell(self, cell):
|
||||||
|
self._unitcell = cell
|
||||||
|
|
||||||
def get_primitive(self):
|
def get_primitive(self):
|
||||||
return self._primitive
|
return self._primitive
|
||||||
|
|
||||||
|
@ -113,8 +117,9 @@ class PhonopyYaml:
|
||||||
nac_factor = self._nac_params['factor']
|
nac_factor = self._nac_params['factor']
|
||||||
dielectric = self._nac_params['dielectric']
|
dielectric = self._nac_params['dielectric']
|
||||||
|
|
||||||
lines.append("phonopy:")
|
if self._version:
|
||||||
lines.append(" version: %s" % self._version)
|
lines.append("phonopy:")
|
||||||
|
lines.append(" version: %s" % self._version)
|
||||||
if self._calculator:
|
if self._calculator:
|
||||||
lines.append(" calculator: %s" % self._calculator)
|
lines.append(" calculator: %s" % self._calculator)
|
||||||
if self._nac_params:
|
if self._nac_params:
|
||||||
|
|
|
@ -212,7 +212,8 @@ class Symmetry:
|
||||||
zip(ops['rotations'], ops['translations'])):
|
zip(ops['rotations'], ops['translations'])):
|
||||||
|
|
||||||
diff = np.dot(pos[i], r.T) + t - pos[eq_atom]
|
diff = np.dot(pos[i], r.T) + t - pos[eq_atom]
|
||||||
if (abs(diff - np.rint(diff)) < self._symprec).all():
|
diff -= np.rint(diff)
|
||||||
|
if np.linalg.norm(diff) < self._symprec:
|
||||||
map_operations[i] = j
|
map_operations[i] = j
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -289,42 +290,4 @@ def get_lattice_vector_equivalence(point_symmetry):
|
||||||
equivalence[0] = True
|
equivalence[0] = True
|
||||||
|
|
||||||
return equivalence
|
return equivalence
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
from phonopy.structure.symmetry import Symmetry
|
|
||||||
from phonopy.interface.vasp import read_vasp
|
|
||||||
|
|
||||||
def get_magmom(text):
|
|
||||||
magmom = []
|
|
||||||
for numxmag in text.split():
|
|
||||||
if '*' in numxmag:
|
|
||||||
num, mag = numxmag.split('*')
|
|
||||||
magmom += [float(mag)] * int(num)
|
|
||||||
else:
|
|
||||||
magmom.append(float(numxmag))
|
|
||||||
return magmom
|
|
||||||
|
|
||||||
def parse_incar(filename):
|
|
||||||
for line in open(filename):
|
|
||||||
for conf in line.split(';'):
|
|
||||||
if 'MAGMOM' in conf:
|
|
||||||
return get_magmom(conf.split('=')[1])
|
|
||||||
|
|
||||||
cell = read_vasp("POSCAR")
|
|
||||||
symmetry = Symmetry(cell, symprec=1e-3)
|
|
||||||
map_nonspin = symmetry.get_map_atoms()
|
|
||||||
print("Number of operations w/o spin %d" %
|
|
||||||
len(symmetry.get_symmetry_operations()['rotations']))
|
|
||||||
magmoms = parse_incar("INCAR")
|
|
||||||
cell.set_magnetic_moments(magmoms)
|
|
||||||
symmetry = Symmetry(cell, symprec=1e-3)
|
|
||||||
print("Number of operations w spin %d" %
|
|
||||||
len(symmetry.get_symmetry_operations()['rotations']))
|
|
||||||
map_withspin = symmetry.get_map_atoms()
|
|
||||||
if ((map_nonspin - map_withspin) == 0).all():
|
|
||||||
print(True)
|
|
||||||
else:
|
|
||||||
print(False)
|
|
||||||
print(map_nonspin)
|
|
||||||
print(map_withspin)
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from phonopy.structure.cells import get_supercell, get_primitive
|
||||||
class TestDynmatToFc(unittest.TestCase):
|
class TestDynmatToFc(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
filename = "POSCAR.yaml"
|
filename = "../NaCl.yaml"
|
||||||
self._cell = get_unitcell_from_phonopy_yaml(filename)
|
self._cell = get_unitcell_from_phonopy_yaml(filename)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
|
@ -35,7 +35,7 @@ class TestPhonopyYaml(unittest.TestCase):
|
||||||
# print(unitcell)
|
# print(unitcell)
|
||||||
|
|
||||||
def _get_phonon(self):
|
def _get_phonon(self):
|
||||||
cell = read_vasp("POSCAR_NaCl")
|
cell = read_vasp("../POSCAR_NaCl")
|
||||||
phonon = Phonopy(cell,
|
phonon = Phonopy(cell,
|
||||||
np.diag([2, 2, 2]),
|
np.diag([2, 2, 2]),
|
||||||
primitive_matrix=[[0, 0.5, 0.5],
|
primitive_matrix=[[0, 0.5, 0.5],
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
lattice:
|
||||||
|
- [ 2.812696943681890, 0.000000000000000, 0.000000000000000 ] # a
|
||||||
|
- [ 0.000000000000000, 2.812696943681890, 0.000000000000000 ] # b
|
||||||
|
- [ 0.000000000000000, 0.000000000000000, 2.812696943681890 ] # c
|
||||||
|
points:
|
||||||
|
- symbol: Cr # 1
|
||||||
|
coordinates: [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]
|
||||||
|
mass: 51.996100
|
||||||
|
- symbol: Cr # 2
|
||||||
|
coordinates: [ 0.500000000000000, 0.500000000000000, 0.500000000000000 ]
|
||||||
|
mass: 51.996100
|
|
@ -0,0 +1,71 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import time
|
||||||
|
|
||||||
|
from phonopy.structure.symmetry import Symmetry
|
||||||
|
from phonopy.structure.cells import get_supercell
|
||||||
|
from phonopy.interface.phonopy_yaml import get_unitcell_from_phonopy_yaml
|
||||||
|
|
||||||
|
class TestSymmetry(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_get_map_operations(self):
|
||||||
|
symprec = 1e-5
|
||||||
|
cell = get_unitcell_from_phonopy_yaml("../NaCl.yaml")
|
||||||
|
scell = get_supercell(cell, np.diag([2, 2, 2]), symprec=symprec)
|
||||||
|
symmetry = Symmetry(scell, symprec=symprec)
|
||||||
|
|
||||||
|
map_ops_cmp = [ 0, 2, 51, 53, 8, 1, 65, 98, 3, 14,
|
||||||
|
34, 24, 76, 69, 54, 110, 576, 198, 229, 208,
|
||||||
|
201, 192, 210, 294, 5, 67, 36, 57, 18, 90,
|
||||||
|
23, 114, 0, 9, 1, 96, 6, 323, 98, 326,
|
||||||
|
3, 42, 17, 293, 16, 130, 99, 337, 192, 194,
|
||||||
|
202, 199, 205, 196, 200, 193, 12, 5, 30, 108,
|
||||||
|
37, 128, 291, 302]
|
||||||
|
start = time.time()
|
||||||
|
symmetry._set_map_operations()
|
||||||
|
end = time.time()
|
||||||
|
# print(end - start)
|
||||||
|
map_ops = symmetry.get_map_operations()
|
||||||
|
self.assertTrue((map_ops_cmp == map_ops).all())
|
||||||
|
|
||||||
|
def test_magmom(self):
|
||||||
|
symprec = 1e-5
|
||||||
|
cell = get_unitcell_from_phonopy_yaml("Cr.yaml")
|
||||||
|
symmetry_nonspin = Symmetry(cell, symprec=symprec)
|
||||||
|
atom_map_nonspin = symmetry_nonspin.get_map_atoms()
|
||||||
|
len_sym_nonspin = len(
|
||||||
|
symmetry_nonspin.get_symmetry_operations()['rotations'])
|
||||||
|
|
||||||
|
spin = [1, -1]
|
||||||
|
cell_withspin = cell.copy()
|
||||||
|
cell_withspin.set_magnetic_moments(spin)
|
||||||
|
symmetry_withspin = Symmetry(cell_withspin, symprec=symprec)
|
||||||
|
atom_map_withspin = symmetry_withspin.get_map_atoms()
|
||||||
|
len_sym_withspin = len(
|
||||||
|
symmetry_withspin.get_symmetry_operations()['rotations'])
|
||||||
|
|
||||||
|
broken_spin = [1, -2]
|
||||||
|
cell_brokenspin = cell.copy()
|
||||||
|
cell_brokenspin = cell.copy()
|
||||||
|
cell_brokenspin.set_magnetic_moments(broken_spin)
|
||||||
|
symmetry_brokenspin = Symmetry(cell_brokenspin, symprec=symprec)
|
||||||
|
atom_map_brokenspin = symmetry_brokenspin.get_map_atoms()
|
||||||
|
len_sym_brokenspin = len(
|
||||||
|
symmetry_brokenspin.get_symmetry_operations()['rotations'])
|
||||||
|
|
||||||
|
self.assertTrue((atom_map_nonspin == atom_map_withspin).all())
|
||||||
|
self.assertFalse((atom_map_nonspin == atom_map_brokenspin).all())
|
||||||
|
self.assertTrue(len_sym_nonspin == len_sym_withspin)
|
||||||
|
self.assertFalse(len_sym_nonspin == len_sym_brokenspin)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestSymmetry)
|
||||||
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||||
|
# unittest.main()
|
|
@ -1,15 +0,0 @@
|
||||||
Na Cl
|
|
||||||
1.00000000000000
|
|
||||||
5.6903014761756712 0.0000000000000000 0.0000000000000000
|
|
||||||
0.0000000000000000 5.6903014761756712 0.0000000000000000
|
|
||||||
0.0000000000000000 0.0000000000000000 5.6903014761756712
|
|
||||||
4 4
|
|
||||||
Direct
|
|
||||||
0.0000000000000000 0.0000000000000000 0.0000000000000000
|
|
||||||
0.0000000000000000 0.5000000000000000 0.5000000000000000
|
|
||||||
0.5000000000000000 0.0000000000000000 0.5000000000000000
|
|
||||||
0.5000000000000000 0.5000000000000000 0.0000000000000000
|
|
||||||
0.5000000000000000 0.5000000000000000 0.5000000000000000
|
|
||||||
0.5000000000000000 0.0000000000000000 0.0000000000000000
|
|
||||||
0.0000000000000000 0.5000000000000000 0.0000000000000000
|
|
||||||
0.0000000000000000 0.0000000000000000 0.5000000000000000
|
|
|
@ -12,7 +12,7 @@ from phonopy.structure.atoms import PhonopyAtoms as Atoms
|
||||||
class TestUnfolding(unittest.TestCase):
|
class TestUnfolding(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._cell = read_vasp("POSCAR")
|
self._cell = read_vasp("../POSCAR_NaCl")
|
||||||
# print(self._cell)
|
# print(self._cell)
|
||||||
self._unfolding = None
|
self._unfolding = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue