Exemple #1
0
def write_xsf(cell, filename=None):
    if filename == None: filename = 'mcu'
    comment = misc.date()
    lattice = np.asarray(cell[0])
    positions = np.asarray(cell[1])
    abs_positions = positions.dot(lattice)
    atoms = np.asarray(cell[2])
    natom = len(atoms)
    symbol = cell_utils.convert_atomtype(atoms)

    with open(filename + '.xsf', 'w') as f:
        f.write('Generated by mcu on ' + comment + '\n')
        f.write('CRYSTAL\n')
        f.write('PRIMVEC\n')
        for i in range(3):
            f.write('   %15.10f %15.10f %15.10f\n' %
                    (lattice[i, 0], lattice[i, 1], lattice[i, 2]))
        f.write('CONVVEC\n')
        for i in range(3):
            f.write('   %15.10f %15.10f %15.10f\n' %
                    (lattice[i, 0], lattice[i, 1], lattice[i, 2]))
        f.write('PRIMCOORD\n')
        f.write('%3d %3d\n' % (natom, 1))
        for atom in range(natom):
            f.write(' %s  %15.10f  %15.10f  %15.10f\n' %
                    (symbol[atom], abs_positions[atom][0],
                     abs_positions[atom][1], abs_positions[atom][2]))
Exemple #2
0
def cell_to_spgcell(cell, atoms):
    '''Providing the cell attribute from vasprun.xml, return the cell for spglib'''

    lattice = np.ndarray.tolist(cell[0])
    positions = np.ndarray.tolist(cell[2])
    numbers = utils.convert_atomtype(atoms)
    return (lattice, positions, numbers)
Exemple #3
0
def write_poscar(cell, filename=None):
    if filename == None: filename = 'POSCAR_mcu'
    comment = misc.date()
    lattice = np.asarray(cell[0])
    positions = np.asarray(cell[1])
    atoms = np.asarray(cell[2])
    idx = np.argsort(atoms)
    atoms = atoms[idx]
    symbol = cell_utils.convert_atomtype(atoms)
    irred_symbol, count = misc.unique(symbol)
    positions = positions[idx]

    with open(filename, 'w') as f:
        f.write('Generated by mcu on ' + comment + '\n')
        f.write('1.0\n')
        for i in range(3):
            f.write('   %15.10f %15.10f %15.10f\n' %
                    (lattice[i, 0], lattice[i, 1], lattice[i, 2]))
        for symb in irred_symbol:
            f.write(' %s ' % (symb))
        f.write('\n')
        for num_atom in count:
            f.write(' %d ' % (num_atom))
        f.write('\n')
        f.write('Direct\n')
        for atom in positions:
            f.write('   %15.10f %15.10f %15.10f\n' %
                    (atom[0], atom[1], atom[2]))
Exemple #4
0
def get_sym(cell, symprec=1e-5, print_atom=False, export_operator=False):

    #Space group info
    intl_label, number = spglib.get_spacegroup(cell, symprec).split(' ')
    number = number.split("(")[1].split(")")[0]
    Schoenflies_label = spglib.get_spacegroup(cell, symprec,
                                              symbol_type=1).split(' ')[0]
    sym = spglib.get_symmetry(cell, symprec)
    rotations = sym['rotations']
    translations = sym['translations']
    equi_atoms = sym['equivalent_atoms']

    is_std = is_prim = False
    std_cell = spglib.refine_cell(cell, symprec)
    prim_cell = spglib.find_primitive(cell, symprec)
    if compare_cells(cell, std_cell): is_std = True
    if compare_cells(cell, prim_cell): is_prim = True

    atoms = utils.convert_atomtype(cell[2])
    if export_operator == False:
        #Cell info
        std_cell = spglib.refine_cell(cell, symprec)
        prim_cell = spglib.find_primitive(cell, symprec)
        #Print
        misc.print_msg("Spacegroup  number           : %s" % (number))
        misc.print_msg("Short International symbol   : %s" % (intl_label))
        misc.print_msg("Schoenflies symbol           : %s" %
                       (Schoenflies_label))
        if print_atom == True:
            misc.print_msg("Atoms list (No. - Sym - Symbol):")
            for i, atom in enumerate(atoms):
                misc.print_msg("%3d   %3d   %s" %
                               (i + 1, equi_atoms[i] + 1, atom))
            misc.print_msg("Irreducible atoms:")
            for i, index in enumerate(np.unique(equi_atoms)):
                misc.print_msg("%3d  %3s    %7f5 %7f5 %7f5" %
                               (i + 1, atoms[index], cell[1][index][0],
                                cell[1][index][1], cell[1][index][2]))
        misc.print_msg("Number of irreducible atoms  : %d" %
                       (np.unique(equi_atoms).shape[0]))
        misc.print_msg("Standard cell                : %r" % (is_std))
        misc.print_msg("Primitive cell               : %r" % (is_prim))
        return is_std, is_prim
    else:
        return (number, intl_label), equi_atoms, rotations, translations
Exemple #5
0
def write_cif(cell, spacegroup, equi_atoms, symopt, filename=None):
    if filename == None: filename = 'mcu'
    comment = misc.date()
    lattice = np.asarray(cell[0])
    lattice = cell_utils.convert_lattice(lattice)
    positions = np.asarray(cell[1])
    atoms = np.asarray(cell[2])
    new_atm = [atoms[atm] for atm in np.unique(equi_atoms)]
    new_pos = [positions[atm] for atm in np.unique(equi_atoms)]
    natom = len(new_atm)
    symbol = cell_utils.convert_atomtype(new_atm)
    nsymopt = len(symopt)

    with open(filename + '.cif', 'w') as f:
        f.write('data_New_Crystal\n')
        f.write("_audit_creation_method         '%s'\n" %
                ('Generated by mcu on ' + comment))
        f.write('_cell_length_a     %15.10f\n' % (lattice[0]))
        f.write('_cell_length_b     %15.10f\n' % (lattice[1]))
        f.write('_cell_length_c     %15.10f\n' % (lattice[2]))
        f.write('_cell_angle_alpha     %15.10f\n' % (lattice[3]))
        f.write('_cell_angle_beta      %15.10f\n' % (lattice[4]))
        f.write('_cell_angle_gamma     %15.10f\n' % (lattice[5]))
        f.write('\n')
        f.write("_symmetry_space_group_name_H-M     '%s'\n" % (spacegroup[1]))
        f.write('_symmetry_Int_Tables_number        %s\n' % (spacegroup[0]))
        f.write('loop_\n')
        f.write('_symmetry_equiv_pos_as_xyz\n')
        for i in range(nsymopt):
            f.write('%s\n' % (symopt[i]))

        f.write('\n')
        f.write('loop_\n')
        f.write('_atom_site_label\n')
        f.write('_atom_site_type_symbol\n')
        f.write('_atom_site_fract_x\n')
        f.write('_atom_site_fract_y\n')
        f.write('_atom_site_fract_z\n')
        for atom in range(natom):
            f.write('   %s   %s   %15.10f   %15.10f   %15.10f\n' %
                    (symbol[atom], symbol[atom], new_pos[atom][0],
                     new_pos[atom][1], new_pos[atom][2]))
Exemple #6
0
    def read_win(self, seedname=None):  
        '''Read the seedname.win file'''
        
        if seedname is None: seedname = self.seedname
        if check_exist(seedname + '.win'):
            with open(seedname + '.win', "r") as file:
                win = file.read().splitlines()

            # Cell information
            lattice = copy_block(win, 'Unit_Cell_Cart', convert_to_float=True)
            atom_block = copy_block(win, 'atoms_cart')
            atom_sym = []
            atom_position = []
            for atm in atom_block:
                temp = atm.split()
                atom_sym.append(temp[0])
                atom_position.append(np.float64(temp[1:]))
            self.atom = atom_sym
            atom_number = utils.convert_atomtype(self.atom )
            self.cell = (lattice, atom_position, atom_number)
            
            # kmesh info
            self.kpts = np.asarray(copy_block(win, 'kpoints', convert_to_float=True))
            self.klabel = None
            kpoint_path = copy_block(win, 'kpoint_path')
            if kpoint_path is not []:
                num_kpoint = len(kpoint_path)
                high_sym_kpoints = []
                for i, kpoint in enumerate(kpoint_path):
                    if i == (num_kpoint - 1):
                        temp = kpoint.split()
                        high_sym_kpoints.append([temp[0], np.float64(temp[1:4])])
                        high_sym_kpoints.append([temp[4], np.float64(temp[5:])])
                    else:
                        temp = kpoint.split()
                        high_sym_kpoints.append([temp[0], np.float64(temp[1:4])])
                self.klabel = high_sym_kpoints
            
        else:
            print('Cannot find the *.win file. Check the path:', seedname + '.win')       
Exemple #7
0
    def read_ouput(self, filename=None):
        '''Read the cp2k output file'''
        if filename is None: filename = self.output

        assert check_exist(
            filename), "Cannot find the output. Check the path: " + filename
        with open(filename, "r") as file:
            outfile = file.read().splitlines()

        # Cell information
        cell_block = copy_block(outfile, "CELL_TOP")
        a_vec = cell_block[1].split()[4:7]
        b_vec = cell_block[2].split()[4:7]
        c_vec = cell_block[3].split()[4:7]
        lattice = np.float64([a_vec, b_vec, c_vec])

        atom_type, atom_position = get_atoms(outfile)
        self.atom = atom_type
        atom_number = utils.convert_atomtype(atom_type)
        self.cell = (lattice, atom_position, atom_number)

        self.efermi = get_value(outfile, keyword="Fermi energy")
        self.kpts = 0  # kmesh info: TODO: will test the Gamma point case first
Exemple #8
0
    def __init__(self,
                 mp_grid,
                 num_wann,
                 wavecar='WAVECAR',
                 poscar='POSCAR',
                 gamma=False,
                 spinors=False,
                 spin_up=True,
                 other_keywords=None):

        self.pos = mcu.POSCAR(poscar)
        self.wave = mcu.WAVECAR(wavecar)
        self.num_wann = num_wann
        self.keywords = other_keywords

        # Collect the pyscf calculation info
        self.num_bands_tot = self.wave.band.shape[-1]
        self.num_kpts_loc = self.wave.band.shape[-2]
        self.mp_grid_loc = mp_grid
        assert self.num_kpts_loc == np.asarray(self.mp_grid_loc).prod()
        self.real_lattice_loc = self.wave.cell[0]
        self.recip_lattice_loc = self.wave.cell[1]
        self.kpt_latt_loc = self.wave.kpts
        self.kpts_abs = self.kpt_latt_loc.dot(self.recip_lattice_loc)
        self.abs_kpts = self.wave.kpts.dot(self.recip_lattice_loc)
        self.num_atoms_loc = len(self.pos.cell[2])
        self.atom_symbols_loc = cell_utils.convert_atomtype(self.pos.cell[2])
        self.atom_atomic_loc = self.pos.cell[2]
        self.atoms_cart_loc = np.asarray(self.pos.cell[1]).dot(
            self.real_lattice_loc)
        self.gamma_only, self.spinors = (0, 0)
        if gamma == True: self.gamma_only = 1
        if spinors == True:
            self.spinors = 1
            self.spin = 0

        # Wannier90_setup outputs
        self.num_bands_loc = None
        self.num_wann_loc = None
        self.nntot_loc = None
        self.nn_list = None
        self.proj_site = None
        self.proj_l = None
        proj_m = None
        self.proj_radial = None
        self.proj_z = None
        self.proj_x = None
        self.proj_zona = None
        self.exclude_bands = None
        self.proj_s = None
        self.proj_s_qaxis = None

        # Input for Wannier90_run
        self.band_included_list = None
        self.A_matrix_loc = None
        self.M_matrix_loc = None
        self.eigenvalues_loc = None

        # Wannier90_run outputs
        self.U_matrix = None
        self.U_matrix_opt = None
        self.lwindow = None
        self.wann_centres = None
        self.wann_spreads = None
        self.spread = None

        # Others
        self.use_bloch_phases = False
        self.check_complex = False
        self.spin_up = spin_up

        if spin_up == True:
            self.spin = 0
            self.mo_energy_kpts = self.wave.band[self.spin]
        else:
            self.spin = 1
            assert self.wave.band.shape[
                0] == 2, 'WAVECAR is from a non spin-polarized calculation: spin_up == True'
            self.mo_energy_kpts = self.wave.band[self.spin]