Beispiel #1
0
 def dump2POSCAR(self, dumpname, poscar='POSCAR', rotate=True):
     atoms = self.atoms_from_dump(dumpname)
     if rotate:
         rot = np.loadtxt(tl.dirname(dumpname) + '/POSCARrot')
         d, p, d1, p1 = rot[:3], rot[3], rot[4:7], rot[7]
         atoms.rotate(d1, -p1, rotate_cell=True)
         atoms.rotate(d, -p, rotate_cell=True)
     # write_vasp(poscar,atoms,sort="True",direct=True,vasp5=True)
     writevasp(atoms, poscar)
     return atoms
Beispiel #2
0
 def dump2POSCAR(self, dumpname, poscar='POSCAR', rotate=True):
     atoms = self.atoms_from_dump(dumpname)
     if rotate:
         rot = np.loadtxt(tl.dirname(dumpname) + '/POSCARrot')
         d, p, d1, p1 = rot[:3], rot[3], rot[4:7], rot[7]
         atoms.rotate(d1, -p1, rotate_cell=True)
         atoms.rotate(d, -p, rotate_cell=True)
     # write_vasp(poscar,atoms,sort="True",direct=True,vasp5=True)
     writevasp(atoms, poscar)
     return atoms
Beispiel #3
0
 def optimize(self):
     mkcd('optimize')
     cp('../minimize/POSCAR', '.')
     atoms = io.read('POSCAR')
     for i in range(100):
         dir = "%i" % i
         mkcd(dir)
         writevasp(atoms)
         forces, stress, energy = self.energyForce()
         pos = atoms.get_scaled_positions()
         pos += forces * 0.01
Beispiel #4
0
 def optimize(self):
     mkcd('optimize')
     cp('../minimize/POSCAR', '.')
     atoms = io.read('POSCAR')
     for i in range(100):
         dir = "%i" % i
         mkcd(dir)
         writevasp(atoms)
         forces, stress, energy = self.energyForce()
         pos = atoms.get_scaled_positions()
         pos += forces * 0.01
Beispiel #5
0
    def run_next(self, dir0, dir, lz):
        m = self.m

        atoms = io.read("POSCAR_" + dir0)
        m.forceThick = True
        cell = atoms.get_cell()
        cell[2][2] = lz
        atoms.set_cell(cell, scale_atoms=True)
        m.atoms = atoms
        self.creatmini(dir)
        atoms = m.atoms_from_dump('%s/range' % dir)
        writevasp(atoms, "POSCAR_" + dir)
Beispiel #6
0
    def run_next(self, dir0, dir, lz):
        m = self.m

        atoms = io.read("POSCAR_" + dir0)
        m.forceThick = True
        cell = atoms.get_cell()
        cell[2][2] = lz
        atoms.set_cell(cell, scale_atoms=True)
        m.atoms = atoms
        self.creatmini(dir)
        atoms = m.atoms_from_dump('%s/range' % dir)
        writevasp(atoms, "POSCAR_" + dir)
Beispiel #7
0
 def getlead(self):
     cd('center')
     left = self.findlead('left')
     right = self.findlead('right')
     cd('..')
     return
     from aces.io.vasp import writevasp
     mkcd('leftlead')
     writevasp(left, 'POSCAR')
     self.runlead()
     cd('..')
     mkcd('rightlead')
     writevasp(right, 'POSCAR')
     self.runlead()
     cd('..')
Beispiel #8
0
 def watoms(self, atoms):
     # atoms.write("structure.xyz")
     writevasp(atoms)
     # write_vasp("POSCAR",atoms,sort="True",direct=True,vasp5=True)
     self.POSCAR2data()
Beispiel #9
0
 def watoms(self, atoms):
     # atoms.write("structure.xyz")
     writevasp(atoms)
     # write_vasp("POSCAR",atoms,sort="True",direct=True,vasp5=True)
     self.POSCAR2data()
Beispiel #10
0
    def rearangefc_center(self, fc, satoms, left, right):
        ax = self.m.negfaxis
        right_idx = satoms.positions[:, ax].argsort()[-1]

        x_right = satoms[right_idx].position[ax]
        left_idx = satoms.positions[:, ax].argsort()[0]

        x_left = satoms[left_idx].position[ax]
        # don't put these after satoms=satoms[order]
        lpos = satoms[left_idx].position
        rpos = satoms[right_idx].position
        # find the index of left part in satoms
        atoms = left.copy()
        # remove the offset
        offset = [0, 0, 0]
        offset[ax] = x_left
        atoms.translate(offset)
        lidx = self.match_idx(atoms, satoms)
        lidx = list(lidx)
        atoms.translate(left.cell[ax])
        lidx1 = self.match_idx(atoms, satoms)
        lidx1 = list(lidx1)
        # find the index of right part in satoms
        atoms = right.copy()
        offset = [0, 0, 0]
        offset[ax] = x_right
        atoms.translate(np.array(offset) - right.cell[ax])

        ridx = self.match_idx(atoms, satoms)
        ridx = list(ridx)
        atoms.translate(-right.cell[ax])
        ridx1 = self.match_idx(atoms, satoms)
        ridx1 = list(ridx1)
        # find the center index
        cidx = []
        for i in range(len(satoms)):
            if i in lidx:
                continue
            if i in ridx:
                continue
            cidx.append(i)
        order = lidx + cidx + ridx
        print(order)
        fccenter = fc[order][:, order]
        oatoms = satoms
        satoms = satoms.copy()
        satoms = satoms[order]
        writevasp(satoms, "POSCAR_ordered")

        cut = self.m.negfcut
        if cut > 0:
            self.elimiPeriodic(satoms, fccenter, cut, left, right, lpos, rpos)
        else:

            # the default assumption is that cell length is larger than interaction length,
            # so for | x x | x x | x x | the interaction of cell 1 and cell 3 is only from periodic and the periodic interction only apparear in between 1 and 3
            # F_13 <==> periodic interaction so if we want to eliminate
            # periodic interaction we only have to set F_13=0

            n1 = len(lidx)
            n2 = len(ridx)
            fccenter[:n1, -n2:] = 0
            fccenter[-n2:, :n1] = 0

        # with this method there is no need to calculate fc for left or right
        # again, it's very important for abinitial calculation.
        order = lidx + lidx1
        fcleft = fc[order][:, order]
        # this is for the situation of 2x1x1 supercell when the cell size if
        # pretty large
        if len(cidx) == 0 and cut > 0:
            satoms = oatoms[order]
            self.elimiPeriodic(satoms, fcleft, cut, left, left, lpos, rpos)
        order = ridx1 + ridx
        fcright = fc[order][:, order]
        if len(cidx) == 0 and cut > 0:
            satoms = oatoms[order]
            self.elimiPeriodic(satoms, fcright, cut, right, right, lpos, rpos)
        return fccenter, fcleft, fcright
Beispiel #11
0
    def findlead(self, end="left", err=0.3):
        """[from center POSCAR find periodic lead POSCAR]

        [the center POSCAR is expected to consist of scatter region and left lead region of 2 layers and
        right lead region of 2 layers. So we can find the lead POSCAR from the two ends with this algorithm.]

        Keyword Arguments:
                end {str} -- [which lead do you want ,can be 'left' and 'right'] (default: {"left"})
                err {number} -- [the tolerence to find an atom ] (default: {0.4})

        Raises:
                Exception -- [end is not set correctly]
        """

        atoms = io.read('SPOSCAR')
        # find the most right atom index
        if end == "right":
            last = -1
            next_last = -2
            next_last1 = -3
        elif end == "left":
            last = 0
            next_last = 1
            next_last1 = 2
        else:
            raise Exception("Unkown value of `end`")
        ax = self.m.negfaxis
        right_idx = atoms.positions[:, ax].argsort()[last]
        ratom = atoms[right_idx]
        print("%s end atom position:" % end, ratom.position)
        # the atoms that has similar y,z to ratom , in our situatoin there is
        # at least two such atoms.
        cross = ~(np.arange(3, dtype='int') == ax)
        fil = norm(atoms.positions[:, cross] - ratom.position[cross],
                   axis=1) < err / 10
        # Don't forget the symbol must be the same.
        # must convert to array
        fil1 = np.array(atoms.get_chemical_symbols()) == ratom.symbol
        fil = fil * fil1
        atoms_inline = atoms[fil]
        assert len(atoms_inline) >= 2
        right_idx1 = atoms_inline.positions[:, ax].argsort()[next_last]
        # waring this index is of atoms_inline but not of atoms
        # catom is what we search
        catom = atoms_inline[right_idx1]
        print("next %s end similar atom position:" % end, catom.position)
        # the possible lattice constant of x direction
        la = np.abs(ratom.position[ax] - catom.position[ax])
        refpos = ratom.position
        unit, isunit = self.findunit(atoms, refpos, la, end, err)
        if (isunit == False).sum() > 1:
            next_last = next_last1
            right_idx1 = atoms_inline.positions[:, ax].argsort()[next_last]
            # waring this index is of atoms_inline but not of atoms
            # catom is what we search
            catom = atoms_inline[right_idx1]
            print("next next %s end similar atom position:" % end,
                  catom.position)
            la = np.abs(ratom.position[ax] - catom.position[ax])
            refpos = ratom.position
            unit, isunit = self.findunit(atoms, refpos, la, end, err)
            assert isunit.all()
        # the possible lattice constant of x direction
        rightx = refpos[ax]
        if end == "right":
            offset = [0, 0, 0]
            offset[ax] = -(rightx - la)
            unit.translate(offset)
        else:
            offset = [0, 0, 0]
            offset[ax] = -(rightx)
            unit.translate(offset)
        unit.cell = atoms.cell
        unit.cell[ax, ax] = la
        ys = unit.positions[:, (ax + 1) % 3]
        order = ys.argsort()
        unit = unit[order]
        from aces.io.vasp import writevasp
        writevasp(unit, 'POSCAR_%s' % end)
        return unit