示例#1
0
def read_crystal(filename):
    f_crystal = open(filename)
    crystal_in = CrystalIn(f_crystal.readlines())
    f_crystal.close()
    tags = crystal_in.get_tags()

    cell = Atoms(cell=tags['lattice_vectors'],
                 symbols=tags['atomic_species'],
                 scaled_positions=tags['coordinates'])

    magmoms = tags['magnetic_moments']
    if magmoms is not None:
        # Print out symmetry information for magnetic cases
        # Original code from structure/symmetry.py
        symmetry = Symmetry(cell, symprec=1e-5)
        print(
            "CRYSTAL-interface: Magnetic structure, number of operations without spin: %d"
            % len(symmetry.get_symmetry_operations()['rotations']))
        print("CRYSTAL-interface: Spacegroup without spin: %s" %
              symmetry.get_international_table())

        cell.set_magnetic_moments(magmoms)
        symmetry = Symmetry(cell, symprec=1e-5)
        print(
            "CRYSTAL-interface: Magnetic structure, number of operations with spin: %d"
            % len(symmetry.get_symmetry_operations()['rotations']))
        print("")

    return cell, tags['conv_numbers']
示例#2
0
def read_castep(filename):
    f_castep = open(filename)
    castep_in = CastepIn(f_castep.readlines())
    f_castep.close()
    tags = castep_in.get_tags()
    # 1st stage is to create Atoms object ignoring Spin polarization. General case.
    cell = Atoms(cell=tags['lattice_vectors'],
                 symbols=tags['atomic_species'],
                 scaled_positions=tags['coordinates'])
    # Analyse spin states and add data to Atoms instance "cell" if ones exist
    magmoms = tags['magnetic_moments']
    if magmoms is not None:
        # Print out symmetry information for magnetic cases
        # Original code from structure/symmetry.py
        symmetry = Symmetry(cell, symprec=1e-5)
        print(
            "CASTEP-interface: Magnetic structure, number of operations without spin: %d"
            % len(symmetry.get_symmetry_operations()['rotations']))
        print("CASTEP-interface: Spacegroup without spin: %s" %
              symmetry.get_international_table())

        cell.set_magnetic_moments(magmoms)
        symmetry = Symmetry(cell, symprec=1e-5)
        print(
            "CASTEP-interface: Magnetic structure, number of operations with spin: %d"
            % len(symmetry.get_symmetry_operations()['rotations']))
        print("")

    return cell
def gencastep(fn, modenum, basis, natom, typatsym, symprec, atpos):
    from phonopy import Phonopy
    import phonopy.structure.spglib as spg
    from phonopy.structure.atoms import PhonopyAtoms as Atoms
    from phonopy.structure.symmetry import Symmetry, find_primitive, get_pointgroup

    fh = open(fn, 'w')
    unitcell = Atoms(symbols=typatsym, cell=basis, positions=atpos)
    pbasis = np.eye(3)
    for i in range(len(basis)):
        pbasis[i] = basis[i] / np.linalg.norm(basis[i])
    symmetry = Symmetry(unitcell, symprec)
    rotations = symmetry.get_symmetry_operations()['rotations']
    translations = symmetry.get_symmetry_operations()['translations']
    print('Space group International symbol: %s' %
          symmetry.get_international_table())

    fh.write('%BLOCK LATTICE_CART\n')
    for bl in basis:
        fh.write('%s\n' % ''.join(' %12.8f' % b for b in bl))
    fh.write('%ENDBLOCK LATTICE_CART\n\n')
    fh.write('%BLOCK POSITIONS_ABS\n')
    for i in range(len(typatsym)):
        fh.write("  %3s   " % typatsym[i])
        fh.write('%s\n' % ''.join(' %12.8f' % p for p in atpos[i].tolist()))
    fh.write('%ENDBLOCK POSITIONS_ABS\n\n')

    fh.write('SYMMETRY_TOL : %f ang\n' % symprec)
    fh.write('SYMMETRY_GENERATE \n')
    fh.write('#KPOINT_MP_GRID : 4 4 4\n#KPOINT_MP_OFFSET : 0.5 0.5 0.5\n')
示例#4
0
文件: crystal.py 项目: gcgs1/phonopy
def read_crystal(filename):
    f_crystal = open(filename)
    crystal_in = CrystalIn(f_crystal.readlines())
    f_crystal.close()
    tags = crystal_in.get_tags()
     
     
    cell = Atoms(cell=tags['lattice_vectors'], 
                 symbols=tags['atomic_species'],
                 scaled_positions=tags['coordinates'])
    
    magmoms = tags['magnetic_moments']
    if magmoms is not None:
        # Print out symmetry information for magnetic cases
        # Original code from structure/symmetry.py
        symmetry = Symmetry(cell, symprec=1e-5)
        print("CRYSTAL-interface: Magnetic structure, number of operations without spin: %d" %
              len(symmetry.get_symmetry_operations()['rotations']))
        print("CRYSTAL-interface: Spacegroup without spin: %s" % symmetry.get_international_table())

        cell.set_magnetic_moments(magmoms)
        symmetry = Symmetry(cell, symprec=1e-5)
        print("CRYSTAL-interface: Magnetic structure, number of operations with spin: %d" %
              len(symmetry.get_symmetry_operations()['rotations']))
        print("")
    
    return cell, tags['conv_numbers']
def gencastep(fn,modenum,basis,natom,typatsym,symprec,atpos):
    from phonopy import Phonopy
    import phonopy.structure.spglib as spg
    from phonopy.structure.atoms import PhonopyAtoms as Atoms
    from phonopy.structure.symmetry import Symmetry, find_primitive, get_pointgroup

    fh=open(fn,'w')
    unitcell = Atoms(symbols=typatsym, cell=basis, positions=atpos)
    pbasis=np.eye(3)
    for i in range(len(basis)):
        pbasis[i]=basis[i]/np.linalg.norm(basis[i])
    symmetry = Symmetry(unitcell, symprec)
    rotations = symmetry.get_symmetry_operations()['rotations']
    translations = symmetry.get_symmetry_operations()['translations']
    print('Space group International symbol: %s' % symmetry.get_international_table())

    fh.write('%BLOCK LATTICE_CART\n')
    for bl in basis:
        fh.write('%s\n' % ''.join(' %12.8f' % b for b in bl))
    fh.write('%ENDBLOCK LATTICE_CART\n\n')
    fh.write('%BLOCK POSITIONS_ABS\n')
    for i in range(len(typatsym)):
        fh.write("  %3s   " % typatsym[i])
        fh.write('%s\n' % ''.join(' %12.8f' % p for p in atpos[i].tolist()))
    fh.write('%ENDBLOCK POSITIONS_ABS\n\n')

    fh.write('SYMMETRY_TOL : %f ang\n' % symprec)
    fh.write('SYMMETRY_GENERATE \n')
    fh.write('#KPOINT_MP_GRID : 4 4 4\n#KPOINT_MP_OFFSET : 0.5 0.5 0.5\n')
示例#6
0
 def test_parse_wien2k_struct(self):
     cell, npts, r0s, rmts = parse_wien2k_struct("BaGa2.struct")
     lattice = cell.get_cell().T
     displacements, supercell = parse_disp_yaml("disp_BaGa2.yaml",
                                                return_cell=True)
     symmetry = Symmetry(cell)
     print(PhonopyAtoms(atoms=cell))
     sym_op = symmetry.get_symmetry_operations()
     print(symmetry.get_international_table())
     for i, (r, t) in enumerate(
             zip(sym_op['rotations'], sym_op['translations'])):
         print("--- %d ---" % (i + 1))
         print(r)
         print(t)
示例#7
0
文件: abinit.py 项目: gcgs1/phonopy
        self._set_x_tags('xred')

    def _set_x_tags(self, tagname):
        xtag = []
        natom = self._tags['natom']
        for val in self._values:
            xtag += self._get_numerical_values(val)
            if len(xtag) >= natom * 3:
                break

        self._tags[tagname] = np.reshape(xtag[:natom * 3], (-1, 3))

    def _set_znucl(self):
        znucl = []
        ntypat = self._tags['ntypat']
        for val in self._values:
            znucl += self._get_numerical_values(val, num_type='int')
            if len(znucl) >= ntypat:
                break

        self._tags['znucl'] = znucl[:ntypat]

if __name__ == '__main__':
    import sys
    from phonopy.structure.symmetry import Symmetry
    abinit = AbinitIn(open(sys.argv[1]).readlines())
    cell = read_abinit(sys.argv[1])
    symmetry = Symmetry(cell)
    print("# %s" % symmetry.get_international_table())
    print(get_abinit_structure(cell))
示例#8
0
文件: lmto.py 项目: gcgs1/phonopy
        self._tags['plat'] = plat

    def _set_alat(self, header):
        hlist = header.split()
        for j in hlist:
            if j.startswith('alat'):
                alat = float(j.split('=')[1])
                break
        self._tags['alat'] = alat    

    def _check_ord(self, header):
        if not 'xpos' in header.split():
            print('EXIT(1): LMTO Interface requires site', end=' ')
            print('files to be in fractional co-ordinates')
            sys.exit(1)
            
    def get_variables(self, header, sites):
        self._check_ord(header)
        self._set_atoms(sites)
        self._set_plat(header)
        self._set_alat(header)
        return self._tags

if __name__ == '__main__':
    import sys
    from phonopy.structure.symmetry import Symmetry
    cell = read_lmto(sys.argv[1])
    symmetry = Symmetry(cell)
    print('# %s' % symmetry.get_international_table())
    print(get_lmto_structure(cell))
示例#9
0
文件: elk.py 项目: ladyteam/phonopy
        self._tags["atoms"] = {"spfnames": spfnames, "positions": positions}

    def _set_avec(self):
        avec = []
        for i in range(3):
            avec.append([float(x) for x in self._lines.pop(0).split()[:3]])
        self._tags["avec"] = avec

    def _set_scale(self):
        scale = float(self._lines.pop(0).split()[0])
        for i in range(3):
            self._tags["scale"][i] = scale

    def _set_scale1(self):
        self._tags["scale"][0] = float(self._lines.pop(0).split()[0])

    def _set_scale2(self):
        self._tags["scale"][1] = float(self._lines.pop(0).split()[0])

    def _set_scale3(self):
        self._tags["scale"][2] = float(self._lines.pop(0).split()[0])


if __name__ == "__main__":
    from phonopy.structure.symmetry import Symmetry

    cell, sp_filenames = read_elk(sys.argv[1])
    symmetry = Symmetry(cell)
    print("# %s" % symmetry.get_international_table())
    print(get_elk_structure(cell, sp_filenames=sp_filenames))
示例#10
0
文件: lmto.py 项目: gcgs1/phonopy
    def _set_alat(self, header):
        hlist = header.split()
        for j in hlist:
            if j.startswith('alat'):
                alat = float(j.split('=')[1])
                break
        self._tags['alat'] = alat

    def _check_ord(self, header):
        if not 'xpos' in header.split():
            print('EXIT(1): LMTO Interface requires site', end=' ')
            print('files to be in fractional co-ordinates')
            sys.exit(1)

    def get_variables(self, header, sites):
        self._check_ord(header)
        self._set_atoms(sites)
        self._set_plat(header)
        self._set_alat(header)
        return self._tags


if __name__ == '__main__':
    import sys
    from phonopy.structure.symmetry import Symmetry
    cell = read_lmto(sys.argv[1])
    symmetry = Symmetry(cell)
    print('# %s' % symmetry.get_international_table())
    print(get_lmto_structure(cell))
示例#11
0
文件: siesta.py 项目: nfh/phonopy
            elif tag == "atomiccoordinatesandatomicspecies":
                lines = block.split('\n')[:-1]
                self._tags["atomiccoordinates"] = [ [float(x)  for x in atom.split()[:3]] for atom in lines ]
                self._tags["atomicspecies"] = [ int(atom.split()[3]) for atom in lines]
       
        #check if the block are present
        self.check_present("atomicspecies")
        self.check_present("atomiccoordinates")
        self.check_present("latticevectors")
        self.check_present("chemicalspecieslabel")
            
        #translate the atomicspecies to atomic numbers
        self._tags["atomicnumbers"] = [self._tags["atomicnumbers"][atype] for atype in self._tags["atomicspecies"]]
    
    def check_present(self,tag):
        if not self._tags[tag]:
            print "%s not present"%tag
            exit()
 
    def __str__():
        return self._tags

        
if __name__ == '__main__':
    import sys
    from phonopy.structure.symmetry import Symmetry
    cell,atypes = read_siesta(sys.argv[1])
    symmetry = Symmetry(cell)
    print "#", symmetry.get_international_table()
    print get_siesta_structure(cell,atypes)
示例#12
0
                ]

        #check if the block are present
        self.check_present("atomicspecies")
        self.check_present("atomiccoordinates")
        self.check_present("latticevectors")
        self.check_present("chemicalspecieslabel")

        #translate the atomicspecies to atomic numbers
        self._tags["atomicnumbers"] = [
            self._tags["atomicnumbers"][atype]
            for atype in self._tags["atomicspecies"]
        ]

    def check_present(self, tag):
        if not self._tags[tag]:
            print "%s not present" % tag
            exit()

    def __str__():
        return self._tags


if __name__ == '__main__':
    import sys
    from phonopy.structure.symmetry import Symmetry
    cell, atypes = read_siesta(sys.argv[1])
    symmetry = Symmetry(cell)
    print "#", symmetry.get_international_table()
    print get_siesta_structure(cell, atypes)
示例#13
0
from anharmonic.phonon3.triplets import get_triplets_at_q
from phonopy.interface.vasp import read_vasp 
from phonopy.structure.symmetry import Symmetry
import numpy as np

cell = read_vasp("POSCAR-unitcell")
symmetry = Symmetry(cell, 1e-2)
print symmetry.get_international_table()
reciprocal_lattice = np.linalg.inv(cell.get_cell())
mesh = [7, 7, 7]

print reciprocal_lattice

(triplets_at_q,
 weights_at_q,
 grid_address,
 bz_map,
 triplets_map_at_q,
 ir_map_at_q)= get_triplets_at_q(74,
                                 mesh,
                                 symmetry.get_pointgroup_operations(),
                                 reciprocal_lattice,
                                 stores_triplets_map=True)

for triplet in triplets_at_q:
    sum_q = (grid_address[triplet]).sum(axis=0)
    if (sum_q % mesh != 0).any():
        print "============= Warning =================="
        print triplet
        for tp in triplet:
            print grid_address[tp], np.linalg.norm(np.dot(reciprocal_lattice, grid_address[tp] / mesh))