Beispiel #1
0
        raise ValueError('NSKIP must be less than num of files given: ',
                         len(infiles))
    infiles.sort(key=get_key, reverse=True)
    del infiles[:nskip]

    na = int(180.0 / dang) + 1
    angd, agr = adf_average(infiles,
                            dang=dang,
                            rcut=rcut,
                            triplets=triplets,
                            no_average=no_average,
                            specorder=specorder)

    if not sigma == 0:
        print(' Gaussian smearing...')
        for it, t in enumerate(triplets):
            agr[it, :] = gsmear(angd, agr[it, :], sigma)

    if flag_plot:
        plot_figures(angd, agr, triplets)
        print('')
        print(' RDF graphes are plotted.')
        print(' Check graph_adf.png')

    if out4fp:
        write_out4fp(ofname, triplets, na, angd, rcut)
    else:
        write_normal(ofname, triplets, na, angd, agr)

    print(' Wrote ' + ofname)
Beispiel #2
0
    nspcs = len(specorder)
    if nspcs < 1:
        raise ValueError('--specorder must be set.')

    if len(infiles) > 1:
        infiles.sort(key=get_key,reverse=True)
    del infiles[:nskip]

    nr= int(rmax/dr) +1
    rd,agr= rdf_average(infiles,nr,specorder,dr=dr,rmax=rmax,
                        pairwise=pairwise)

    if not sigma == 0:
        print(' Gaussian smearing...')
        #...Smearing of total RDF
        agrt= gsmear(rd,agr[0,0],sigma)
        agr[0,0,:] = agrt[:]
        #...Smearing of inter-species RDF
        for isid in range(1,nspcs+1):
            for jsid in range(1,nspcs+1):
                agrt= gsmear(rd,agr[isid,jsid],sigma)
                agr[isid,jsid,:] = agrt[:]

    if out4fp:
        write_out4fp(ofname,specorder,nspcs,agr,nr,rmax,pairs)
    else:
        write_normal(ofname,specorder,nspcs,rd,agr,nr,)

    if plot:
        plot_figures(rd,agr)
        print('')
Beispiel #3
0
def main():
    args = docopt(__doc__.format(os.path.basename(sys.argv[0])))

    infiles = args['INFILE']
    dr = float(args['-d'])
    rmax = float(args['--rmax'])
    rmin = float(args['--rmin'])
    sigma = int(args['--gsmear'])
    nnmax = int(args['--nnmax'])
    ofname = args['-o']

    if ofname == 'None':
        ofname = None
    specorder = [x for x in args['--specorder'].split(',')]
    if specorder == ['None']:
        specorder = []
    plot = args['--plot']
    nskip = int(args['--skip'])
    SQ = args['--SQ']
    if SQ:
        qmax = float(args['--qmax'])
        qmin = float(args['--qmin'])
        lscatter = [float(x) for x in args['--scatter-length'].split(',')]
        if len(lscatter) != len(specorder):
            raise ValueError('--scatter-length is not set correctly.')
    out4fp = args['--out4fp']
    fortran = args['--fortran']
    if out4fp and ofname is None:
        raise ValueError("Output file name must be specified with option -o.")
    if out4fp and not SQ:
        pairwise = True
        pairs0 = args['--pairs'].split(',')
        pairs = []
        for pair in pairs0:
            spi, spj = pair.split('-')
            try:
                isid = specorder.index(spi) + 1
            except:
                isid = 0
            try:
                jsid = specorder.index(spj) + 1
            except:
                jsid = 0
            if jsid < isid:
                itmp = jsid
                jsid = isid
                isid = itmp
            pairs.append((isid, jsid))
    else:
        no_pairwise = args['--no-pairwise']
        pairwise = not no_pairwise
        pairs = None

    nspcs = len(specorder)
    if nspcs < 1:
        raise ValueError('--specorder must be set.')

    if len(infiles) > 1:
        infiles.sort(key=get_key, reverse=True)
    del infiles[:nskip]
    if len(infiles) < 1:
        raise ValueError('No input files to be processed.')
    print(infiles)

    tiny = 1.0e-8
    nr = int((rmax - rmin + tiny) / dr) + 1
    rd, agr = rdf_average(infiles,
                          specorder,
                          dr=dr,
                          rmin=rmin,
                          rmax=rmax,
                          pairwise=pairwise,
                          nnmax=nnmax,
                          fortran=fortran)

    if not sigma == 0:
        #print(' Gaussian smearing...')
        #...Smearing of total RDF
        agrt = gsmear(rd, agr[0, 0, :], sigma)
        agr[0, 0, :] = agrt[:]
        #...Smearing of inter-species RDF
        for isid in range(1, nspcs + 1):
            for jsid in range(isid, nspcs + 1):
                agrt = gsmear(rd, agr[isid, jsid, :], sigma)
                agr[isid, jsid, :] = agrt[:]

    if SQ:
        nsys = nappy.io.read(infiles[0])
        rho = float(nsys.num_atoms()) / nsys.get_volume()
        if nspcs > 1:
            #...Redfine total RDF as weighted sum of g_{ij}(r) in case of multiple species
            natms = [float(nsys.num_atoms())]
            cs = [1.0]
            for ispcs in range(1, nspcs + 1):
                natms.append(float(nsys.num_atoms(ispcs)))
                cs.append(natms[ispcs] / natms[0])
            bmean = 0.0
            for isid in range(1, nspcs + 1):
                bi = lscatter[isid - 1]
                ci = cs[isid]
                bmean += ci * bi
            agr[0, 0, :] = 0.0
            for isid in range(1, nspcs + 1):
                bi = lscatter[isid - 1]
                ci = cs[isid]
                for jsid in range(isid, nspcs + 1):
                    bj = lscatter[jsid - 1]
                    cj = cs[jsid]
                    wij = ci * cj * bi * bj / bmean
                    if isid == jsid:
                        agr[0, 0, :] += agr[isid, jsid, :] * wij
                    else:
                        agr[0, 0, :] += 2.0 * agr[isid, jsid, :] * wij
        qs, sqs = gr_to_SQ(rd, agr[0, 0, :], rho, qmin=0.7, qmax=qmax, nq=200)

    #...Regardless ofname, write out.rdf in normal format
    write_rdf_normal(
        'out.rdf',
        specorder,
        nspcs,
        rd,
        agr,
        nr,
    )
    if SQ:
        write_sq_out4fp('out.sq', qs, sqs)
    #...Format of output (named by ofname) depends on out4fp
    if ofname is not None:
        if out4fp:
            write_rdf_out4fp(ofname,
                             specorder,
                             nspcs,
                             agr,
                             nr,
                             rmax,
                             pairs=pairs,
                             rmin=rmin)
        else:
            write_rdf_normal(
                ofname,
                specorder,
                nspcs,
                rd,
                agr,
                nr,
            )

    if plot:
        plot_figures(specorder, rd, agr)
        print('')
        print(' RDF graphes are plotted.')
        if nspcs == 1:
            print(' Check graph_rdf_total.png')
        else:
            print(' Check graph_rdf_total.png and graph_rdfs.png')
    else:
        print(' Check out.rdf with gnuplot, like')
        print("   gnuplot> plot 'out.rdf' us 1:2  w l")
        print('')
        if ofname is not None:
            print(" In addition to out.rdf, {0:s} is also written.".format(
                ofname))
            print('')

    return None
Beispiel #4
0
def rdf_of_atom(ia, nsys, rmax=5.0, dr=0.1, sigma=0):
    """
    Compute RDF of specified atom.
    """
    #...Radial points
    nr = int(rmax / dr) + 1
    rd = np.array([dr * ir + dr / 2 for ir in range(nr)], )

    nspcs = len(nsys.specorder)
    ndri = np.zeros((nspcs + 1, nr), dtype=float)
    spos = nsys.get_scaled_positions()
    sids = nsys.atoms.sid
    natm = nsys.num_atoms()
    pi = spos[ia]
    hmat = nsys.get_hmat()
    #...Compute ndr of atom-ia
    for ja in nsys.neighbors_of(ia, rcut=rmax):
        pj = spos[ja]
        jsid = sids[ja]
        pij = pj - pi
        pij = pij - np.round(pij)
        vij = np.dot(hmat, pij)
        rij2 = np.dot(vij, vij)
        rij = np.sqrt(rij2)
        ir = int(rij / dr)
        ndri[0, ir] += 1.0
        ndri[jsid, ir] += 1.0

    #...Normalize to get raw RDF(ia)
    #.....Total RDF(ia)
    tmp = 4.0 * np.pi * (natm - 1) * dr
    for ir in range(1, nr):
        r = dr * ir
        ndri[0, ir] /= tmp * r * r
    #.....Species-decomposed RDF(ia)
    natms = [float(natm)]
    for isp in range(1, nspcs + 1):
        natms.append(float(nsys.num_atoms(isp)))
    vol = nsys.get_volume()
    isid = sids[ia]
    tmp0 = 4.0 * np.pi * dr / vol
    for jsid in range(1, nspcs + 1):
        nj = natms[jsid]
        if jsid == isid:
            tmp = tmp0 * (nj - 1)
        else:
            tmp = tmp0 * nj
        for ir in range(1, nr):
            r = dr * ir
            ndri[jsid, ir] /= tmp * r * r

    rdfi = np.zeros(ndri.shape)
    #...Gaussian smearing
    if not sigma == 0:
        #...Total
        rdfi[0, :] = gsmear(rd, ndri[0, :], sigma)
        #...Species-decomposed
        for jsid in range(1, nspcs + 1):
            rdfi[jsid, :] = gsmear(rd, ndri[jsid, :], sigma)

    return rd, rdfi
Beispiel #5
0
def nbplot(nsys, dr=0.1, rmin=0.0, rmax=5.0, nnmax=200, pairs=None, sigma=0):
    """
    Plot RDFs of given nsys on the jupyter notebook.
    """
    if not 'JPY_PARENT_PID' in os.environ:
        raise Exception('This routine must be called on jupyter notebook.')

    import matplotlib.pyplot as plt
    try:
        import seaborn as sns
        sns.set(context='talk', style='ticks')
    except:
        pass

    nspcs = len(nsys.specorder)
    try:
        nr = int((rmax - rmin) / dr) + 1
        rd, gr = rdf(nsys, nspcs, dr, nr, rmax, rmin=rmin, nnmax=nnmax)
    except:
        raise Exception('rdf(..) failed.')

    if sigma > 0:
        #...Smearing of total RDF
        grt = gsmear(rd, gr[0, 0, :], sigma)
        gr[0, 0, :] = grt[:]
        #...Smearing of inter-species RDF
        for isid in range(1, nspcs + 1):
            for jsid in range(isid, nspcs + 1):
                grt = gsmear(rd, gr[isid, jsid, :], sigma)
                gr[isid, jsid, :] = grt[:]

    plt.figure(figsize=(8, 6))
    x = rd
    if not pairs:
        for i in range(nspcs):
            isp = i + 1
            spi = nsys.specorder[i]
            for j in range(nspcs):
                jsp = j + 1
                spj = nsys.specorder[j]
                if j < i:
                    continue
                y = gr[isp, jsp, :]
                plt.plot(x, y, label='{0:s}-{1:s}'.format(spi, spj))
    else:  # only specified pairs are plotted in addition to total RDF
        for p in pairs:
            spi, spj = p
            try:
                isp = nsys.specorder.index(spi) + 1
                jsp = nsys.specorder.index(spj) + 1
            except:
                raise ValueError('No such species or pairs.')
            y = gr[isp, jsp, :]
            plt.plot(x, y, label='{0:s}-{1:s}'.format(spi, spj))

    #...Total RDF
    y = gr[0, 0, :]
    plt.plot(x, y, 'r--', label='Total RDF')

    plt.xlabel('Distance ($\mathrm{\AA}$)')
    plt.ylabel('RDF')
    plt.legend(bbox_to_anchor=(1.05, 1))
    plt.show()
    return None
Beispiel #6
0
def main():
    args = docopt(__doc__.format(os.path.basename(sys.argv[0])))

    infiles = args['INFILE']
    triplets = args['--triplets']
    specorder = [x for x in args['--specorder'].split(',')]
    if specorder == ['None']:
        specorder = []
    if triplets == 'None':
        raise ValueError('Triplets must be specified.')
    triplets = [t.split('-') for t in triplets.split(',')]
    if len(triplets) == 0:
        raise ValueError('There must be at least one triplet.')
    out4fp = args['--out4fp']
    dang = float(args['-w'])
    drad = np.pi * dang / 180.0
    rcut = float(args['-r'])
    nnmax = int(args['--nnmax'])
    sigma = int(args['--gsmear'])
    fortran = args['--fortran']
    ofname = args['-o']
    if ofname == 'None':
        ofname = None
    flag_plot = args['--plot']
    nskip = int(args['--skip'])

    if out4fp and ofname is None:
        raise ValueError("Output file name must be specified with option -o.")

    if nskip > len(infiles):
        raise ValueError('NSKIP must be less than num of files given: ',
                         len(infiles))
    if len(infiles) > 1:
        infiles.sort(key=get_key, reverse=True)
    if nskip > 0 and len(infiles) > nskip:
        del infiles[:nskip]

    na = int(180.0 / dang)
    angd, agr = adf_average(infiles,
                            dang=dang,
                            rcut=rcut,
                            triplets=triplets,
                            specorder=specorder,
                            fortran=fortran,
                            nnmax=nnmax)

    if not sigma == 0:
        print(' Gaussian smearing...')
        for it, t in enumerate(triplets):
            agr[it, :] = gsmear(angd, agr[it, :], sigma)

    if flag_plot:
        plot_figures(angd, agr, triplets)
        print('')
        print(' RDF graphes are plotted.')
        print(' Check graph_adf.png')

    #...Regardless ofname, write out.adf in normal format
    write_normal('out.adf', triplets, na, angd, agr)
    #...Format of output (named by ofname) depends on out4fp
    if ofname is not None:
        if out4fp:
            write_out4fp(ofname, triplets, na, angd, agr, rcut)
        else:
            write_normal(ofname, triplets, na, angd, agr)

    print(' Wrote out.adf')
    if ofname is not None:
        print(' Wrote {0:s}'.format(ofname))
    return None