コード例 #1
0
ファイル: rdf_general.py プロジェクト: petervanya/DPDcoeffs
def rdf_2types(dumpfiles, sp):
    """Construct an rdf for water beads from given xyz frames
    Compute radial dist'n fcn from the xyz frame using 
    Fortran routine for pair distances and numpy binning
    for one particle type.
    Similar to rdf_1type."""
    rdf = np.zeros(len(bins)-1)
    L = cell[0, 0]
    r = sp.bins[:-1] + np.diff(sp.bins)/2.0
    dr = r[1] - r[0]
    A = ll.read_xyzfile(dumpfiles[0])
    N1 = len(A[A[:, 0] == sp.atom_types[0]][:, 1:])
    N2 = len(A[A[:, 0] == sp.atom_types[1]][:, 1:])
    norm = N1*N2

    for dump in dumpfiles:
        A = ll.read_xyzfile(dump)
        xyz1 = A[A[:, 0] == sp.atom_types[0]][:, 1:]
        xyz2 = A[A[:, 0] == sp.atom_types[1]][:, 1:]
        print("Atoms: %i %i | Calculating rdf..." % (N1, N2))

        if sp.use_cutoff:
            nn = int(2*max(N1, N2)**2 * (sp.rc/L)**3 * sp.bc)
            print("Guessed distance vector size: %i | BG: %.2f" % (nn, sp.bc))
            dist_vec = f_rdf.dist_vec_cut_2mat(xyz1, xyz2, sp.rc, L, sp.cell, nn)
            dist_vec = dist_vec[dist_vec != 0.0]
        else:
            dist_vec = f_rdf.dist_vec_2mat(xyz1, xyz2, cell)

        rdf_raw, _ = np.histogram(dist_vec, sp.bins)
        rdf += rdf_raw /(4*pi*r**2 * dr) * L**3 / norm
        print("Done: %s" % dump)
    return rdf / sp.Nd
コード例 #2
0
ファイル: diffusivity1.py プロジェクト: petervanya/PhDcode
def check_beadtypes(bt, frame):
    """Check if beadtype present in the xyz frame"""
    A = read_xyzfile(frame)
    bts = set(A[:, 0].astype(int))
    if bt not in bts:
        sys.exit("Bead type %i not found in frame." % bt)
    return
コード例 #3
0
ファイル: rdf_ptfe2.py プロジェクト: petervanya/PhDcode
def rdf_water(outfiles, sp):
    """Rdf for water beads from given xyz frames"""
    rdf = np.zeros(len(sp.bins) - 1)
    L = sp.cell[0, 0]
    r = sp.bins[:-1] + np.diff(sp.bins) / 2.0
    dr = r[1] - r[0]

    A = ll.read_xyzfile(outfiles[0])
    NC = len(A[A[:, 0] == 3])
    NW = len(A[A[:, 0] == 4])
    Norm_C = NC * (NC - 1) / 2
    Norm_W = NW * (NW - 1) / 2
    Norm_CW = NC * NW
    mem = NC * NW * 8 / (1024)**3

    print("Computing water. C beads: %i | W beads: %i | Memory: %.1f GB" %\
          (NC, NW, mem))

    for outfile in outfiles:
        A = ll.read_xyzfile(outfile)
        xyz_C = A[A[:, 0] == 3][:, 1:]
        xyz_W = A[A[:, 0] == 4][:, 1:]

        print("Calculating rdf... ", end="", flush=True)
        dist_vec_C = f_rdf.dist_vec(xyz_C, sp.cell)
        rdf_raw_C, _ = np.histogram(dist_vec_C, sp.bins)
        del dist_vec_C
        print("Done.\nCalculating rdf... ", end="", flush=True)
        dist_vec_W = f_rdf.dist_vec(xyz_W, sp.cell)
        rdf_raw_W, _ = np.histogram(dist_vec_W, sp.bins)
        del dist_vec_W
        print("Done.\nCalculating rdf... ", end="", flush=True)
        dist_vec_CW = f_rdf.dist_vec_2mat(xyz_C, xyz_W, sp.cell)
        rdf_raw_CW, _ = np.histogram(dist_vec_CW, sp.bins)
        del dist_vec_CW
        print(outfile, "done.")

        rdf_raw = rdf_raw_C * 3**2 / Norm_C + \
                  rdf_raw_W * 6**2 / Norm_W + \
                  rdf_raw_CW * 3*6 / Norm_CW
        rdf += rdf_raw / (4*pi*r**2 * dr) * L**3 / (3**2 + 6**2 + 3*6)
    return rdf
コード例 #4
0
ファイル: rdf_general.py プロジェクト: petervanya/DPDcoeffs
def rdf_1type(dumpfiles, sp):
    """Construct an rdf for water beads from given xyz frames.
    Compute radial dist'n fcn from the xyz frame using 
    Fortran routine for pair distances and numpy binning
    for one particle type.
    Input:
    * dumpflies: list of xyz frame names
    * sp: system params, containing:
        * atom_type: integer
        * rc: cutoff for atom neighbourhood
        * cell: (3, 3) matrix
        * bins: vector
        * bc: Bulgarian const to guess the distance vector size
    """
    rdf = np.zeros(len(sp.bins)-1)
    L = sp.cell[0, 0]
    r = sp.bins[:-1] + np.diff(sp.bins)/2.0
    dr = r[1] - r[0]

    A = ll.read_xyzfile(dumpfiles[0])
    N1 = len(A[A[:, 0] == sp.atom_types[0]])
    norm = N1*(N1-1)/2


    for dump in dumpfiles:
        A = ll.read_xyzfile(dump)
        xyz = A[A[:, 0] == sp.atom_types[0]][:, 1:]
        print("Calculating rdf...")

        if sp.use_cutoff:
            nn = int(2* N1**2 * (sp.rc/L)**3 * sp.bc)  # guess of dist vec length
            print("Guessed distance vector size: %i | BG: %.2f" % (nn, sp.bc))
            dist_vec = f_rdf.dist_vec_cut(xyz, sp.rc, L, sp.cell, nn)
            dist_vec = dist_vec[dist_vec != 0.0]
        else:
            dist_vec = f_rdf.dist_vec(xyz, cell)

        rdf_raw, _ = np.histogram(dist_vec, sp.bins)
        rdf += rdf_raw / (4*pi*r**2 * dr) * L**3 / norm
        print("Done: %s" % dump)
    return rdf / sp.Nd
コード例 #5
0
ファイル: rdf_ptfe2.py プロジェクト: petervanya/PhDcode
def rdf_1type(outfiles, sp):
    """Rdf for given bead type from all the available xyz frames"""
    rdf = np.zeros(len(sp.bins) - 1)
    L = sp.cell[0, 0]
    r = sp.bins[:-1] + np.diff(sp.bins) / 2.0
    dr = r[1] - r[0]

    A = ll.read_xyzfile(outfiles[0])
    N1 = len(A[A[:, 0] == sp.beadtype])
    Norm = N1 * (N1-1) / 2

    for outfile in outfiles:
        A = ll.read_xyzfile(outfile)
        xyz = A[A[:, 0] == sp.beadtype][:, 1:]
        print("Calculating rdf... ", end="", flush=True)
        dist_vec = f_rdf.dist_vec(xyz, cell)
        print("Done.\nBinning dist vec... ", end="", flush=True)
        rdf_raw, _ = np.histogram(dist_vec, sp.bins)
        print(outfile, "done.")
        rdf += rdf_raw / (4*pi*r**2 * dr) * L**3 / Norm
    return rdf / sp.Nf
コード例 #6
0
def guess_directions(frame):
    """Guess directions x, y, z (0, 1, 2) from the frame:
    * two parallel to the slab
    * one perpendicular
    """
    A = read_xyzfile(frame)
    xyz = A[A[:, 0] == 4][:, 1:4]
    mins, maxs = np.zeros(3), np.zeros(3)
    diffs = np.zeros(3)
    for i in range(3):
        mins[i], maxs[i] = min(xyz[:, i]), max(xyz[:, i])
    diffs = maxs - mins
    perp = (np.argmin(diffs),)
    parr = tuple(set(np.arange(3)).difference(perp))
    print("Guessing directions. Perp:", perp, "| Parr:", parr)
    return perp, parr
コード例 #7
0
ファイル: rdf_ptfe_water.py プロジェクト: petervanya/PhDcode
def compute_rdf_water(outfile, rc, cell, bins):
    """Compute radial dist'n fcn from the xyz frame using 
    Fortran routine for pair distances and numpy binning
    """
    A = ll.read_xyzfile(outfile)
    xyz_C = A[A[:, 0] == 3][:, 1:]
    xyz_W = A[A[:, 0] == 4][:, 1:]
    NC = len(xyz_C)
    NW = len(xyz_W)
    print("NC:", NC, "| NW:", NW,"| Calculating rdf...")

    r = bins[:-1] + np.diff(bins)/2.0
    dr = bins[1] - bins[0]
    L = cell[0, 0]

    nn = int(2*NW**2 * (rc/L)**3 * 1.3)  # bulgarian const
    print("W beads, memory size:", nn*8/(1024.0)**3, "GB")
    d_W = f_rdf.dist_vec_cut(xyz_W, rc, L, cell, nn)  # rdf for W beads
    d_W = d_W[d_W != 0.0]
    print("Real size:", len(d_W)*8/(1024.0)**3, "GB")
    rdf_W, _ = np.histogram(d_W, bins)
    del d_W
    rdf_W = rdf_W /(4*np.pi*r**2 * dr) * L**3 / (NW*(NW-1)/2)

    nn = int(2*NC**2 * (rc/L)**3 * 1.3)
    print("C beads, memory size:", nn*8/(1024.0)**3, "GB")
    d_C = f_rdf.dist_vec_cut(xyz_C, rc, L, cell, nn)  # rdf for C beads
    d_C = d_C[d_C != 0.0]
    print("Real size:", len(d_C)*8/(1024.0)**3, "GB")
    rdf_C, _ = np.histogram(d_C, bins)
    del d_C
    rdf_C = rdf_C /(4*np.pi*r**2 * dr) * L**3 / (NC*(NC-1)/2)

    nn = int(2*NW**2 * (rc/L)**3 * 1.3)
    print("C and W beads, memory size:", nn*8/(1024.0)**3, "GB")
    d_CW = f_rdf.dist_vec_cut_2mat(xyz_C, xyz_W, rc, L, cell, nn)  # rdf for combined C and W beads
    d_CW = d_CW[d_CW != 0.0]
    print("Real size:", len(d_CW)*8/(1024.0)**3, "GB")
    rdf_CW, _ = np.histogram(d_CW, bins)
    del d_CW
    rdf_CW = rdf_CW /(4*np.pi*r**2 * dr) * L**3 / (NC*NW)

    norm = 6**2 + 3**2 + 6*3
    rdf = (rdf_W * 6**2 + rdf_C * 3**2 + rdf_CW * 6*3) / norm
    return rdf
コード例 #8
0
ファイル: rdf_ptfe.py プロジェクト: petervanya/PhDcode
    outfiles = glob.glob(args["<fnames>"])
    beadtype = "water" if args["water"] else args["<b>"]
    if len(outfiles) == 0:
        raise ValueError("No xyz files captured, aborting.")
    print(outfiles)
    Nfiles = len(outfiles)
    N = int(open(outfiles[0], "r").readline())
    L = float(args["--L"])
    
    if args["--bins"]:
        Nbins = int(args["--bins"])
    else:
        Nbins = set_num_bins(N, method="sturges")
    method = args["--binalg"]

    A = ll.read_xyzfile(outfiles[0])
    Nbt = len(set(A[:, 0]))
    Nb = len(A[A[:, 0] == int(beadtype)])

    print("Total beads: %i | Num. beadtypes: %i | Bins: %i" % (N, Nbt, Nbins))
    print("Bead type: %s | Beads of this type: %i" % (beadtype, Nb))
    
    if beadtype == "water":
        r, vals = master_rdf_water(outfiles, L, Nbins, method)
        fname = "rdf_water.out"
    else:
        r, vals = master_rdf(outfiles, L, int(beadtype), Nbins)
        fname = "rdf.out"
    save_data(fname, r, vals)
    print("rdf saved in", fname)
コード例 #9
0
ファイル: op_new.py プロジェクト: petervanya/PhDcode
    raw = 2 * N12 / rN12 / (N11 / rN11 + N22 / rN22)
    print("=====\n4th method: raw = 2 * N12/rN12 / (N11/rN11 + N22/rN22)")
    print("OP: 1 / raw = %.3f\n=====" % (1.0 / raw))


if __name__ == "__main__":
    args = docopt(__doc__)
    rc = float(args["--rc"])

    if not args["test"]:
        print("===== New order parameter ====")
        frames = glob.glob(args["<frames>"])
        Nf = len(frames)
        if Nf == 0:
            sys.exit("No files captured.")
        A = read_xyzfile(frames[0])
        N = len(A)
        L = guess_box_size(A[:, 1:])
        Nx = int(L // rc)    # choose largest possible cell number
        print("Frames: %i | N: %i | Nx: %i | Box: %.2f" % (Nf, N, Nx, L))

        OP = 0.0
        ti = time.time()
        for frame in frames:
            A = read_xyzfile(frame)
            types, xyz = A[:, 0], A[:, 1:]   # TO DO: convert types to {1, 2}
            N1, N2 = len(types == 1), len(types == 2)
            rN11 = N1*(N1-1)/2
            rN22 = N2*(N2-1)/2
            rN12 = N1*N2
コード例 #10
0
    for a in na:
        dr = xyz[a] - r0
        G = inv_box @ dr
        Gn = G - np.round(G)
        drn = box @ Gn
        pt += smear_func(drn, sigma, rc)
#    if pt != 0.0: print("%.2f   " % pt, end="")
    return pt


if __name__ == "__main__":
    args = docopt(__doc__)
    frame = args["<frame>"]
    if os.path.isfile(frame):
        A = ll.read_xyzfile(frame)
    else:
        sys.exit("File %s not found." % frame)
    if len(A) > 1000:
        L = guess_box_size(A)
    else:
        L = 40.0
    sigma = float(args["--sigma"])
    rc = float(args["--cut"]) * sigma

    Nx = int(args["--nx"])
    if rc > (L / Nx):
        print("Warning: Smear function rc larger than link cell size.")

    dx = float(args["--grid"])
    x = np.arange(dx/2, L, dx)
コード例 #11
0
ファイル: si2dpd.py プロジェクト: petervanya/PTFEsim
#!/usr/bin/env python
"""Usage:
   si2dpd.py <infile> [--rc <rc>]

[AD HOC] Modify xyz files by converting metres to DPD units
to conform with VMD standards.

Options:
    --rc <rc>      DPD units [default: 8.14e-10]
    

[email protected], 11/01/16
"""
import numpy as np
from docopt import docopt
import lmp_lib as ll

args = docopt(__doc__)
rc = float(args["--rc"])
print("rc = %.2e" % rc)

A = ll.read_xyzfile(args["<infile>"])
A[:, 1:] /= rc
outfile = "converted.xyz"
ll.save_xyzfile(outfile, A)
print("xyz frame in DPD units saved in", outfile)
コード例 #12
0
ファイル: rdf_ptfe2.py プロジェクト: petervanya/PhDcode

if __name__ == "__main__":
    args = docopt(__doc__)
    if args["test"]:
        print("Testing rdf")
        test_me()
        sys.exit()
    
    outfiles = glob.glob(args["<fnames>"])
    if len(outfiles) == 0:
        raise ValueError("No xyz files captured.")
    Nf = len(outfiles)
    N = int(open(outfiles[0], "r").readline())
    Nbins = float(args["--bins"])
    A = ll.read_xyzfile(outfiles[0])
    Nbt = len(set(A[:, 0]))

    if args["--L"]:
        L = float(args["--L"])
    else:
        xyz = ll.read_xyzfile(dumpfiles[0])
        L = guess_box_size(xyz)

    cell = L * np.eye(3)
    bins = np.linspace(0, L/2, Nbins+1)
    r = bins[:-1] + np.diff(bins)/2.0
    
    print("===== Calculating PTFE rdf ====")
    print("Box size: %.2f | Beads: %i | Bins: %i | Frames: %i" %\
         (L, N, Nbins, Nf))
コード例 #13
0
ファイル: rdf_general.py プロジェクト: petervanya/DPDcoeffs
if __name__ == "__main__":
    args = docopt(__doc__)
#    print(args)
    dumpfiles = glob.glob(args["<files>"])
    if len(dumpfiles) == 0:
        print("No xyz files captured.")
        sys.exit()
    Nd = len(dumpfiles)
    N = int(open(dumpfiles[0], "r").readline())
    Nbins = int(args["--bins"])

    if args["--L"]:
        L = float(args["--L"])
    else:
        xyz = ll.read_xyzfile(dumpfiles[0])
        L = guess_box_size(xyz)

    use_cutoff = False
    rc = -1.0
    if args["--cutoff"]:
        rc = float(args["--cutoff"])
        use_cutoff = True
    bins = np.linspace(0, L/2, Nbins+1)
    r = bins[:-1] + np.diff(bins)/2.0
    
    atom_types = [int(i) for i in args["--types"].split()]
    if len(atom_types) > 2:
        print("Only two atom types allowed for rdf calculation.")
        sys.exit()
    xyz_types = set(ll.read_xyzfile(dumpfiles[0])[:, 0])