Esempio n. 1
0
def main(args):
    infname = args['FILE']

    aSys = read(fname=infname)
    natm = len(aSys.atoms)

    outfname = infname + ".voro"
    f = open(outfname, 'w')
    alc = aSys.alc
    ax = aSys.a1[0]
    ay = aSys.a2[1]
    az = aSys.a3[2]
    for ia in range(natm):
        pos = aSys.atoms[ia].pos
        f.write(' {0:4d}'.format(ia + 1))
        f.write(' {0:10.3f}'.format(alc * ax * pos[0]))
        f.write(' {0:10.3f}'.format(alc * ay * pos[1]))
        f.write(' {0:10.3f}'.format(alc * az * pos[2]))
        f.write('\n')
    f.close()

    print('Use voro++ as follows:')
    cmd= 'voro++ -p -c " %i %q %v %s %A"' \
        +' 0.0 {0:5.1f}'.format(alc*ax) \
        +' 0.0 {0:5.1f}'.format(alc*ay) \
        +' 0.0 {0:5.1f}'.format(alc*az) \
        +' {0:s}'.format(outfname)

    print('$ ' + cmd)
    os.system(cmd)
Esempio n. 2
0
File: adf.py Progetto: ryokbys/nap
def adf_average(infiles,
                dang=1.0,
                rcut=3.0,
                triplets=[],
                specorder=None,
                fortran=False,
                nnmax=100):
    na = int(180.0 / dang)
    aadf = np.zeros((len(triplets), na), dtype=float)
    nsum = 0
    for infname in infiles:
        if not os.path.exists(infname):
            print("[Error] File, {0}, does not exist !!!".format(infname))
            sys.exit()
        #nsys= NAPSystem(fname=infname,specorder=specorder)
        print(' File = ', infname)
        nsys = read(fname=infname, specorder=specorder)
        angd, df = adf(nsys,
                       dang,
                       rcut,
                       triplets,
                       fortran=fortran,
                       nnmax=nnmax)
        #...NOTE that df is not averaged over the atoms in nsys
        aadf += df
        nsum += 1
    if nsum != 0:
        aadf /= nsum
    return angd, aadf
Esempio n. 3
0
    sgm = float(args['--sigma'])
    if sgm < 0.0:
        sgm = abs(sgm) * width
    specorder = args['--specorder'].split(',')
    if 'None' in specorder and not files[0].find('POSCAR') > -1:
        raise ValueError(
            'ERROR: specorder must be specified, unless files are POSCAR format.'
        )

    if sid == 0:
        raise ValueError('ERROR: sid should be specified and should not be 0.')

    files.sort(key=get_key, reverse=True)

    #nsys0 = NAPSystem(fname=files[0],specorder=specorder)
    nsys0 = read(fname=files[0], specorder=specorder)
    a, b, c = nsys0.get_lattice_angles()
    if abs(a-np.pi/2) > 180.0/np.pi or abs(b-np.pi/2) > 180.0/np.pi \
       or abs(c-np.pi/2) > 180.0/np.pi:
        raise ValueError(
            'ERROR: Currently only available for orthogonal lattice, a,b,c=',
            a, b, c)
    ndivs = get_num_division(nsys0, width)
    if np.dot(ndivs, ndivs) > 10000000:
        raise ValueError('ERROR: ndivs too large.', ndivs)
    else:
        print(' # of divisions = {0:d} {1:d} {2:d}'.format(*ndivs))

    pdist = np.zeros(ndivs, dtype=float)
    for f in files:
        print(' Reading {0:s}...'.format(f))
Esempio n. 4
0
def get_msd(files, ids0, nmeasure, nshift, specorder=None):
    """
    Compute MSD of specified species-ID from sequential structure FILES.
    
    Parameters
    ----------

    files: list
         List of files used for the MSD calculation.
    ids0: list
         List of atom-IDs (starting from 1) whose MSDs are to be computed.
    nmeasure: int
         Number of staggered lanes to compute MSD for better statistics.
    nshift: int
         Number of files to be skipped for each staggered lane.
    specorder: list
         Order of species.

    Returns
    -------
    msd : Numpy array of dimension, (len(files),nmeasure,3).
    """
    nsys = read(fname=files[0], specorder=specorder)
    if specorder is None:
        specorder = copy.copy(nsys.specorder)
    # if specorder is not None:
    #     #nsys = NAPSystem(fname=files[0],specorder=specorder)
    # else:
    #     nsys = NAPSystem(fname=files[0],)
    #     specorder = copy.copy(nsys.specorder)

    nspc = len(specorder)
    if ids0 is not None:
        ids = [i - 1 for i in ids0]
        sids = nsys.atoms.sid
        naps = [0 for i in len(specorder)]
        for i in ids0:
            sid = sids[i]
            naps[sid - 1] += 1
    else:
        ids = [i for i in range(nsys.num_atoms())]
        naps = nsys.natm_per_species()

    symbols = nsys.get_symbols()
    p0 = np.zeros((nmeasure, len(ids), 3))
    pp = np.zeros((len(ids), 3))
    # msd= np.zeros((len(files),nmeasure,nspc,3))
    msd = np.zeros(
        (len(files) - (nmeasure - 1) * nshift + 1, nmeasure, nspc, 3))
    npbc = np.zeros((len(ids), 3))
    hmat = np.zeros((3, 3))
    for ifile in range(len(files)):
        fname = files[ifile]
        sys.stdout.write(
            '\r{0:5d}/{1:d}: {2:s}'.format(ifile + 1, len(files), fname), )
        sys.stdout.flush()
        if ifile != 0:
            #nsys= NAPSystem(fname=fname,specorder=specorder)
            nsys = read(fname=fname, specorder=specorder)
        poss = nsys.get_scaled_positions()
        sids = nsys.atoms.sid

        hmat = nsys.get_hmat()
        for ia, idi in enumerate(ids):
            # #...human-readable ID to computer-oriented ID
            # i= idi - 1
            pi = poss[idi]
            sid = sids[idi] - 1
            if ifile == 0:
                pp[ia, :] = pi[:]
            else:
                #...correct periodic motion
                dev = pi - pp[ia]
                if dev[0] > 0.5:
                    npbc[ia, 0] += -1.0
                elif dev[0] < -0.5:
                    npbc[ia, 0] += 1.0
                if dev[1] > 0.5:
                    npbc[ia, 1] += -1.0
                elif dev[1] < -0.5:
                    npbc[ia, 1] += 1.0
                if dev[2] > 0.5:
                    npbc[ia, 2] += -1.0
                elif dev[2] < -0.5:
                    npbc[ia, 2] += 1.0
                # print npbc
                #...store current position
                pp[ia, :] = pi[:]

            for nm in range(nmeasure):
                if ifile == nm * nshift:
                    p0[nm, ia, 0] = pi[0] + npbc[ia, 0]
                    p0[nm, ia, 1] = pi[1] + npbc[ia, 1]
                    p0[nm, ia, 2] = pi[2] + npbc[ia, 2]
                if nm * nshift < ifile <= (nm + 1) * nshift:
                    #...normalized to absolute
                    dev[0] = pi[0] + npbc[ia, 0] - p0[nm, ia, 0]
                    dev[1] = pi[1] + npbc[ia, 1] - p0[nm, ia, 1]
                    dev[2] = pi[2] + npbc[ia, 2] - p0[nm, ia, 2]
                    dev = np.dot(hmat, dev)
                    msd[ifile - nm * nshift, nm, sid, 0] += dev[0]**2
                    msd[ifile - nm * nshift, nm, sid, 1] += dev[1]**2
                    msd[ifile - nm * nshift, nm, sid, 2] += dev[2]**2

    for ifile in range(len(files)):
        for nm in range(nmeasure):
            if nm * nshift < ifile <= (nm + 1) * nshift:
                msd[ifile - nm * nshift, nm, :, 0] /= naps[:]
                msd[ifile - nm * nshift, nm, :, 1] /= naps[:]
                msd[ifile - nm * nshift, nm, :, 2] /= naps[:]

    print('')
    return msd, specorder
Esempio n. 5
0
if __name__ == '__main__':
    
    args = docopt(__doc__)
    niter = int(args['-n'])
    dltmax = float(args['-d'])
    mdexec = args['--mdexec']

    if niter < 2:
        raise ValueError('NITER {0:d} should be larger than 1.'.format(niter))

    if niter % 2 == 0:
        niter += 1

    #nsys0 = NAPSystem(fname='pmdini')
    nsys0 = read('pmdini')
    os.system('cp pmdini pmdini.bak')
    hmat0 = nsys0.get_hmat()
    print('Original H-matrix:')
    print(hmat0)
    # al,hmat0,natm= read_pmd()
    hmax= np.max(hmat0)
    print('Maximum in H-matrix elements = ',hmax)

    outfile1= open(outfname,'w')
    #...get reference energy
    os.system(mdexec+' > out.pmd')
    erg0 = float(subprocess.check_output("cat erg.pmd",shell=True))
    #erg0= float(commands.getoutput("grep 'potential energy' out.pmd | tail -n1 | awk '{print $3}'"))
    # print ' {0:10.4f} {1:15.7f} {2:15.7f} {3:15.7f}'.format(0.0,erg0,erg0,erg0)
    # outfile1.write(' {0:10.4f} {1:15.7f} {2:15.7f} {3:15.7f}\n'.format(0.0,erg0,erg0,erg0))
Esempio n. 6
0
def main(args):

    id_file = args['-f']
    measure = args['--measure']

    #
    # usage= '%prog [options] akr0001 akr0002 akr0003 ...'
    #
    # parser= optparse.OptionParser(usage=usage)
    # parser.add_option("--id",dest="id",type="int",default=1,
    #                   help="id of an atom whose path is to be traced.")
    # parser.add_option("-f","--file",dest="id_file",type="string",default=None,
    #                   help="file name which contains the list of IDs of atoms whose paths are to be traced.")
    # parser.add_option("-m","--measure",dest="measure",type="int",default=1,
    #                   help="num of measuring lane. In case of 1, it is identical to non-staggered measuring.")
    # parser.add_option("--sid",dest="sid",type="int",default=0,
    #                   help="species-ID to be selected for power spectrum calculation.")
    # parser.add_option("-s","--shift",dest="shift",type="int",default=20,
    #                   help="shift of each staggered lane.")
    # parser.add_option("-t","--time-interval",dest="tval",type="float",
    #                   default=1.0,
    #                   help="time interval between successive akr files in [fs].")
    # parser.add_option("--relax",dest="trlx",type="float",
    #                   default=1e+10,
    #                   help="relaxation time [fs] of decaying factor.")
    # (options,args)= parser.parse_args()

    #...file name of the ID list
    #idfile= options.id_file
    idfile = args['--file']
    #...atom IDs whose trajectories are tracked.
    if idfile is None:
        # id = options.id
        atomid = int(args['--id'])
    #...num of measuring lane, in case of 1, it is identical to non-staggered measuring
    #nmeasure= options.measure
    nmeasure = int(args['--measure'])
    #...shift of each staggered lane
    #nshift= options.shift
    nshift = int(args['--shift'])
    #...species-ID
    #sid= options.sid
    sid = int(args['--sid'])
    #...time interval
    #tval= options.tval
    #trlx= options.trlx
    tval = float(args['--time-interval'])
    trlx = float(args['--relax'])

    print(' idfile=', idfile)
    print(' id=', id)
    print(' nmeasure=', nmeasure)
    print(' nshift=', nshift)
    print(' sid=', sid)
    print(' tval=', tval)
    print(' len(args)=', len(args))
    # sys.exit()

    #...parse arguments
    infiles = args['INFILE']
    infiles.sort(key=get_key, reverse=True)

    #...compute sampling time-window from nmeasure and nshift
    ntwindow = len(infiles) - (nmeasure - 1) * nshift
    print(' ntwindow=', ntwindow)
    if ntwindow <= 0:
        print(' [Error] ntwindow <= 0 !!!')
        print('  Chech the parameters nmeasure and nshift, and input files.')
        sys.exit()

    #...set global values
    infile = infiles[0]
    #system=NAPSystem(fname=infile)
    system = read(fname=infile)
    natm = len(system.atoms)
    psid = np.zeros((natm, ), dtype=np.int8)
    nas = 0
    for ia in range(natm):
        if sid == 0:
            psid[ia] = 1
            nas += 1
        elif system.atoms[ia].sid == sid:
            psid[ia] = 1
            nas += 1
    print(' num of all atoms = ', natm)
    print(' num of atoms to be considered = ', nas)

    print(' accumurating data', end='')
    actmp = np.zeros((nmeasure, ntwindow, 3))
    acorr = np.zeros((ntwindow, 3))
    v02 = np.zeros((nmeasure, natm, 3))
    v2 = np.zeros((ntwindow, nmeasure, natm, 3))
    hmat = np.zeros((3, 3))
    for ifile in range(len(infiles)):
        print('.', end='')
        sys.stdout.flush()
        infile = infiles[ifile]
        #system= NAPSystem(fname=infile)
        system = read(fname=infile)
        hmat[0] = system.a1 * system.alc
        hmat[1] = system.a2 * system.alc
        hmat[2] = system.a3 * system.alc
        atoms = system.atoms

        for im in range(nmeasure):
            if ifile == im * nshift:
                for ia in range(natm):
                    if psid[ia] == 0:
                        continue
                    vi = atoms[ia].vel
                    v02[im, ia, 0] = vi[0]
                    v02[im, ia, 1] = vi[1]
                    v02[im, ia, 2] = vi[2]
            if ifile >= im * nshift and ifile - im * nshift < ntwindow:
                for ia in range(natm):
                    if psid[ia] == 0:
                        continue
                    vi = atoms[ia].vel
                    v2[ifile - im * nshift, im, ia, 0] = vi[0] * v02[im, ia, 0]
                    v2[ifile - im * nshift, im, ia, 1] = vi[1] * v02[im, ia, 1]
                    v2[ifile - im * nshift, im, ia, 2] = vi[2] * v02[im, ia, 2]
    print(' ')

    #.....output auto correlation function
    print(' writing dat.autocorr...')
    acfname = 'dat.autocorr'
    acfile = open(acfname, 'w')
    acfile.write(
        '#      t [fs],   Cvv(t)x,    Cvv(t)y,    Cvv(t)z,   Cvv(t)\n')
    ac = np.zeros((len(infiles) - (nmeasure - 1) * nshift, 3))
    for it in range(len(infiles) - (nmeasure - 1) * nshift):
        for im in range(nmeasure):
            acm = np.zeros(3)
            for ia in range(natm):
                if psid[ia] == 0:
                    continue
                vdenom= v02[im,ia,0]**2 \
                        +v02[im,ia,1]**2 \
                        +v02[im,ia,2]**2
                acm[0] += v2[it, im, ia, 0] / vdenom
                acm[1] += v2[it, im, ia, 1] / vdenom
                acm[2] += v2[it, im, ia, 2] / vdenom
            ac[it, 0] += acm[0] / nas
            ac[it, 1] += acm[1] / nas
            ac[it, 2] += acm[2] / nas
        decay = np.exp(-it * tval / trlx)
        ac[it, 0] = ac[it, 0] / nmeasure * decay
        ac[it, 1] = ac[it, 1] / nmeasure * decay
        ac[it, 2] = ac[it, 2] / nmeasure * decay
        acfile.write(' {0:10.1f}'.format(it*tval) \
                     +' {0:15.7f}'.format(ac[it,0]) \
                     +' {0:15.7f}'.format(ac[it,1]) \
                     +' {0:15.7f}'.format(ac[it,2]) \
                     +' {0:15.7f}\n'.format(ac[it,0]+ac[it,1]+ac[it,2]))
    acfile.close()

    #.....output power spectrum
    print(' writing dat.power...')
    psfname = 'dat.power'
    psfile = open(psfname, 'w')
    mmax = ntwindow / 2
    psfile.write(
        '#     w[cm^-1],      Ix(w),     Iy(w),     Iz(w),     I(w)\n')
    speed = 299792458.0 * 100 / 1.0e+15  # cm/fs
    for mw in range(mmax):
        ps = np.zeros(3)
        for it in range(ntwindow):
            coswt = np.cos(2.0 * np.pi * mw * it / ntwindow)
            ps[:] += ac[it, :] * coswt
        ps[:] = ps[:] * tval / np.pi
        psfile.write(' {0:15.2f}'.format(float(mw)/(ntwindow*tval)/speed) \
                     +' {0:15.7f}'.format(ps[0]) \
                     +' {0:15.7f}'.format(ps[1]) \
                     +' {0:15.7f}'.format(ps[2]) \
                     +' {0:15.7f}\n'.format(ps[0]+ps[1]+ps[2]) )
    psfile.close()
Esempio n. 7
0
def main(args):

    files = args['FILES']
    if len(files) > 1:
        files.sort(key=get_key, reverse=True)
    nskip = int(args['--skip'])
    del files[:nskip]
    prefix = args['--prefix']
    out4fp = args['--out4fp']

    nsum = 0
    volsum = 0.0
    asum = bsum = csum = 0.0
    alpsum = betsum = gmmsum = 0.0
    for i, fi in enumerate(files):
        try:
            nsys = read(fname=fi)
            volsum += nsys.get_volume()
            a, b, c, alpha, beta, gamma = nsys2lat(nsys)
            asum += a
            bsum += b
            csum += c
            alpsum += alpha
            betsum += beta
            gmmsum += gamma
            nsum += 1
        except Exception as e:
            print('Failed {0:s} '.format(fi))
            pass

    if nsum < 1:
        raise ValueError('Something went wrong! nsum<1')
    vol = volsum / nsum
    a = asum / nsum
    b = bsum / nsum
    c = csum / nsum
    alpha = alpsum / nsum
    beta = betsum / nsum
    gamma = gmmsum / nsum

    #...Regardless of prefix, write out.vol and out.lat
    with open('out.vol', 'w') as f:
        f.write('{0:15.3f}\n'.format(vol))
    with open('out.lat', 'w') as f:
        f.write(' {0:10.3f} {1:10.3f} {2:10.3f}'.format(a, b, c) +
                ' {0:10.3f} {1:10.3f} {2:10.3f}\n'.format(alpha, beta, gamma))
    #...Format of output (named by prefix) depends on out4fp
    if out4fp:
        with open(prefix + '.vol', 'w') as f:
            f.write('# Volume\n')
            f.write('     1     1.0\n')
            f.write('{0:15.3f}\n'.format(vol))
        with open(prefix + '.lat', 'w') as f:
            f.write('# Lattice parameters\n')
            f.write('     6     1.0\n')
            f.write(
                ' {0:10.3f} {1:10.3f} {2:10.3f}'.format(a, b, c) +
                ' {0:10.3f} {1:10.3f} {2:10.3f}\n'.format(alpha, beta, gamma))
    else:
        with open(prefix + '.vol', 'w') as f:
            f.write('{0:15.3f}\n'.format(vol))
        with open(prefix + '.lat', 'w') as f:
            f.write(
                ' {0:10.3f} {1:10.3f} {2:10.3f}'.format(a, b, c) +
                ' {0:10.3f} {1:10.3f} {2:10.3f}\n'.format(alpha, beta, gamma))

    print(' Wrote {0:s}.vol {0:s}.lat'.format(prefix))
Esempio n. 8
0
def main(args):
    outfname = args['-o']
    infname = args['INFILE']
    rcut = float(args['-c'])
    maxcoord = int(args['--maxcoord'])
    out4fp = args['--out4fp']

    pairstr = args['--pairs'].split(',')
    pairs = []
    for pair in pairstr:
        try:
            ci, cj = pair.split('-')
        except Exception:
            raise
        pairs.append((ci, cj))
    if len(pairs) == 0:
        raise ValueError('len(pairs) == 0 !!')

    try:
        nsys = read(fname=infname)
    except Exception:
        raise

    coords = count(nsys, pairs, rcut=rcut, maxcoord=maxcoord)

    cmd = ' '.join(s for s in sys.argv)
    if out4fp:
        nperline = 6
        with open(outfname, 'w') as f:
            f.write('# Output at {0:s} from,\n'.format(
                datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
            f.write('#  {0:s}\n'.format(cmd))
            ndat = len(pairs) * maxcoord
            f.write('  {0:6d}  {1:7.3f}\n'.format(ndat, 1.0))
            data = np.zeros(ndat)
            inc = 0
            for p in pairs:
                si, sj = p
                coord = coords[p]
                for i in range(1, maxcoord + 1):
                    data[inc] = coord[i]
                    inc += 1
            j0 = 0
            while True:
                f.write(' '.join('{0:8.1f}'.format(data[j])
                                 for j in range(j0, j0 + nperline)
                                 if j < ndat))
                f.write('\n')
                j0 += nperline
                if j0 >= ndat:
                    break
        print(' Wrote ', outfname)
    else:
        with open(outfname, 'w') as f:
            f.write('# Output at {0:s} from,\n'.format(
                datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
            f.write('#  {0:s}\n'.format(cmd))
            f.write('#   center, neighbor,  coordination histogram \n')
            for p in pairs:
                si, sj = p
                coord = coords[p]
                f.write('  {0:s}  {1:s} '.format(si, sj))
                for i in range(1, maxcoord + 1):
                    f.write(' {0:8.1f}'.format(coord[i]))
                f.write('\n')
        print(' Wrote ', outfname)

    return None
Esempio n. 9
0
def to_given_vector(infile, specorder, a1new, a2new, a3new):
    #psys = NAPSystem(fname=infile,specorder=specorder)
    psys = read(fname=infile, specorder=specorder)
    psys.assign_pbc()
    psys.a1 = psys.a1 * psys.alc
    psys.a2 = psys.a2 * psys.alc
    psys.a3 = psys.a3 * psys.alc
    psys.alc = 1.0
    print('a1  = ', psys.a1)
    print('a2  = ', psys.a2)
    print('a3  = ', psys.a3)

    pos = psys.get_real_positions()
    spos = psys.get_scaled_positions()
    for i in range(min(len(psys.atoms), 10)):
        a = psys.atoms[i]
        print('{0:5d} {1:s}'.format(a.id, a.symbol) +
              ' {0:12.5f} {1:12.5f} {2:12.5f}'.format(spos[i, 0], spos[
                  i, 1], spos[i, 2]) + ' {0:12.5f} {1:12.5f} {2:12.5f}'.format(
                      pos[i, 0], pos[i, 1], pos[i, 2]))

    # print(psys.get_scaled_positions())
    # print(psys.get_real_positions())
    # sa1new = np.zeros(3,dtype=float)
    # sa2new = np.zeros(3,dtype=float)
    # sa3new = np.zeros(3,dtype=float)
    #tmp = raw_input('Input new a1 vector: ')
    #a1new[:] = [ float(x) for x in tmp.split(',') ]
    # sa1new[:] = [ 0.5, 0.5, 0.0]
    #tmp = raw_input('Input new a2 vector: ')
    #a2new[:] = [ float(x) for x in tmp.split(',') ]
    # sa2new[:] = [ 0.0, 1.0, 0.0 ]
    #tmp = raw_input('Input new a3 vector: ')
    #a3new[:] = [ float(x) for x in tmp.split(',') ]
    # sa3new[:] = [ 0.5, 0.5, 1.0 ]
    hmat = psys.get_hmat()
    a1new = np.dot(hmat, sa1new)
    a2new = np.dot(hmat, sa2new)
    a3new = np.dot(hmat, sa3new)
    print('new a1 in hmat_orig =', sa1new)
    print('new a2 in hmat_orig =', sa2new)
    print('new a3 in hmat_orig =', sa3new)
    print('new a1 =', a1new)
    print('new a2 =', a2new)
    print('new a3 =', a3new)
    psnew = NAPSystem(specorder=specorder)
    psnew.set_lattice(psys.alc, a1new, a2new, a3new)

    # Expand the original system for the search of atoms to be included
    # in the new system.
    # First, compute how much we have to expand the original system
    hi = np.linalg.inv(hmat)
    icsa1new = [0, 0, 0]
    icsa2new = [0, 0, 0]
    icsa3new = [0, 0, 0]
    for i in range(3):
        if sa1new[i] < 0.0:
            icsa1new[i] = int(sa1new[i] - 1.0)
        else:
            icsa1new[i] = int(sa1new[i] + 1.0)
        if sa2new[i] < 0.0:
            icsa2new[i] = int(sa2new[i] - 1.0)
        else:
            icsa2new[i] = int(sa2new[i] + 1.0)
        if sa3new[i] < 0.0:
            icsa3new[i] = int(sa3new[i] - 1.0)
        else:
            icsa3new[i] = int(sa3new[i] + 1.0)
    print(icsa1new)
    print(icsa2new)
    print(icsa3new)
    for i in range(3):
        if icsa1new[i] == 0:
            raise RuntimeError('icsa1new[i] == 0')
        if icsa2new[i] == 0:
            raise RuntimeError('icsa2new[i] == 0')
        if icsa3new[i] == 0:
            raise RuntimeError('icsa3new[i] == 0')
    irange1 = (min(icsa1new[0], icsa2new[0],
                   icsa3new[0]), max(icsa1new[0], icsa2new[0], icsa3new[0]))
    irange2 = (min(icsa1new[1], icsa2new[1],
                   icsa3new[1]), max(icsa1new[1], icsa2new[1], icsa3new[1]))
    irange3 = (min(icsa1new[2], icsa2new[2],
                   icsa3new[2]), max(icsa1new[2], icsa2new[2], icsa3new[2]))

    print('irange1: ', irange1)
    print('irange2: ', irange2)
    print('irange3: ', irange3)
    expos = []
    symbols = psys.get_symbols()
    print('symbols :', symbols)
    exsymbols = []
    print('Expanding the original system...')
    for n3 in range(min(0, irange3[0]), irange3[1]):
        for n2 in range(min(0, irange2[0]), irange2[1]):
            for n1 in range(min(0, irange1[0]), irange1[1]):
                for ia in range(len(spos)):
                    sposi = copy.deepcopy(spos[ia])
                    sposi[0] += n1
                    sposi[1] += n2
                    sposi[2] += n3
                    posi = np.dot(hmat, sposi)
                    symbol = symbols[ia]
                    # print(ia,n1,n2,n3,symbol,sposi)
                    expos.append(posi)
                    exsymbols.append(symbol)

    print('Extracting the atoms inside the new unit vectors...')
    hmat = psnew.get_hmat()
    hi = np.linalg.inv(hmat)
    for ia, posi in enumerate(expos):
        sposi = np.dot(hi, posi)
        if 0.0 <= sposi[0] < 1.0 and \
           0.0 <= sposi[1] < 1.0 and \
           0.0 <= sposi[2] < 1.0:
            atom = Atom()
            symbol = exsymbols[ia]
            print('{0:5d} {1:s}'.format(ia, symbol) +
                  ' {0:12.5f} {1:12.5f} {2:12.5f}'.format(
                      sposi[0], sposi[1], sposi[2]))

            atom.set_symbol(symbol)
            atom.set_pos(sposi[0], sposi[1], sposi[2])
            psnew.add_atom(atom)

    tmp = None
    #tmp = raw_input('Input periodic shift vector if you want: ')
    tmp = ' 0.5, 0.0, 0.5'
    if tmp:
        shift = [float(x) for x in tmp.split(',')]
        for a in psnew.atoms:
            a.pos[0] += shift[0]
            a.pos[1] += shift[1]
            a.pos[2] += shift[2]
        psnew.assign_pbc()
    psnew.write_POSCAR(infile + '.new')
    print('Check ' + infile + '.new')