示例#1
0
    elif args["lammps"]:
        # ===== pair coeffs
        a_ij_lmp = {}
        for k in a_ij.keys():
            k_new = " ".join([str(bt2num[i]) for i in k.split()])
            a_ij_lmp[k_new] = a_ij[k]
        for v in a_ij.values():
            v[1], v[2] = v[2], v[1]  # swap gamma/rc

        # ===== molecular ids
        Nmol = Nw + Nelb + Nc  # total num of molecules
        mol_ids = list(range(1, Nw+Nelb+1))
        for i in range(Nw+Nelb+1, Nmol+1): #(1, Nc+1):   # chains
            mol_ids += [i]*Nbc

        xyz_str = ll.atoms2str(np.hstack((np.matrix(mol_ids).T,\
                               np.matrix(atom_ids_n).T, xyz)))
        # ===== bonds
        bond_mat = gen_bonds(Nmc, Nc, mono_beads, start=Nw+Nelb)
        bonds_str = ll.bonds2str2(bond_mat)
        print("%i bonds created." % len(bond_mat))

        data_string = ll.header2str(len(xyz), len(bond_mat), Nbt, len(k_ij), L) + \
                      ll.mass2str(masses) + \
                      ll.pair_dpd_coeffs2str(a_ij_lmp) + \
                      ll.bond_coeffs2str(k_ij) + \
                      "Atoms\n\n" + xyz_str + \
                      "Bonds\n\n" + bonds_str

        fname = "nafion.data"
        open(fname, "w").write(data_string)
        print("Data file saved in", fname)
    L = float(args["--L"])
    rho = float(args["--rho"])
    np.random.seed(1234)

    Nb = int(rho * L**3)
    Nc = int(Nb / N)
    rc = 1.0
    mu = rc / 2.0

    print("=== Creating LAMMPS data file for diblock copolymer melt ===")
    print("Set interaction params in the input file")
    print("Box: %.1f | Rho: %.1f | Chain length: %i | A beads/chain: %i" % \
          (L, rho, N, int(N*f) ))

    poly_xyz = grow_polymer(L, f, N, Nc, mu)
    xyz_str = ll.atoms2str(poly_xyz)
    print(len(poly_xyz), "beads created, density:", len(poly_xyz) / L**3)

    bonds = gen_bonds(N, Nc)
    bonds_str = ll.bonds2str(bonds)
    print(len(bonds), "bonds created")

    final_string = ll.header2str(len(poly_xyz), len(bonds), 2, 1, L) + \
                   ll.mass2str({1: 1.0, 2: 1.0}) + \
                   "\nAtoms\n\n" + xyz_str +  \
                   "\nBonds\n\n" + bonds_str

    fname = "diblock.data"
    open(fname, "w").write(final_string)
    print("Data file written in", fname)
    else:
        sys.exit("<L> should have size 1 or 3.")
    if f < 0.0 or f > 1.0:
        sys.exit("f should be between 0 and 1.")

    Nb = int(rho * np.prod(L))
    Nc = int(Nb / N)
    rc = 1.0
    
    print("=== Creating LAMMPS data file for diblock copolymer melt ===")
    print("Set interaction params in the input file")
    print("Box: %s | Rho: %.1f | Chain length: %i | A beads/chain: %i" % \
          (L, rho, N, int(N*f) ))
    
    poly_xyz = grow_polymer(L, f, N, Nc, mu=1.0)
    xyz_str = ll.atoms2str(poly_xyz)
    print(len(poly_xyz), "beads created, density:", len(poly_xyz) / L**3)

    bonds = gen_bonds(N, Nc)
    bonds_str = ll.bonds2str(bonds)
    print(len(bonds), "bonds created")

    final_string = ll.header2str(len(poly_xyz), len(bonds), 2, 1, L[0]) + \
                   ll.mass2str({1: 1.0, 2: 1.0}) + \
                   "\nAtoms\n\n" + xyz_str +  \
                   "\nBonds\n\n" + bonds_str
    
    fname = "diblock.data"
    open(fname, "w").write(final_string)
    print("Data file written in", fname)
示例#4
0
    if args["--density"] == "real":
        print "Using real density, rho_PMMA = 1180, rho_water = 1000"
        Vw = pw * L**3
        Nc = int(num_chains(rho_PMMA, L, n))     # number of PMMA chains
        if args["water"]:
            nw = int(rho_water * vw/(m_sol*mau))
        elif args["meth"]:
            nw = int(rho_meth * vw/(m_sol*mau))
    else:
        print "Using DPD bead density = 3"
        Nw = int(pw * rho_DPD/rc**3 * L**3)
        Nc = int((1-pw) * rho_DPD/rc**3 * L**3/n)
    poly_xyz = grow_polymer(L, n, Nc, mu=rc, sigma=rc/10)
    water_xyz = gen_water_beads(L, Nw, count=Nc+1)
    final_xyz = np.vstack((poly_xyz, water_xyz))
    xyz_str = ll.atoms2str(final_xyz)
    print len(final_xyz), "beads created, density:", len(final_xyz) / (L/rc)**3

    # ===== bonds
    bonds = create_bonds(n, Nc)
    bonds_str = ll.bonds2str(bonds)
    print len(bonds), "bonds created"

    # ===== pair and bond parameters
    Nbt = len(bead_types)
    r0 = 0.85 * rc     # from Dorenbos, JCP, 2015
    a_ij = gen_pair_coeffs(bead_types, data["ksi-params"], gamma, rc, a_ii)
    k_ij = gen_bond_coeffs(bead_types, data["bond-coeffs"], r0)
    masses = {1: m_PMMA*MAU, 2: m_sol*MAU}

    final_string = ll.header2str(len(final_xyz), len(bonds), Nbt, len(k_ij), L) + \