Ejemplo n.º 1
0
def poscar2dump(pcarFile, lmpFile, scale=None):
    try:
        poscar = open(pcarFile, "r").readlines()
        lammps = open(lmpFile, "w")
    except IOError:
        print "Error: %s Unable to open POSCAR/Lammps file." % sys.argv[0].split("/")[-1]
        usage()
        exit(0)

    if scale == None:
        scale = 1.0

    [basis, atypes, atoms, head, poscar] = poscarIO.read(poscar)

    # Convert from POSCAR style basis vectors to LAMMPS style boundaries.
    xhi, yhi, zhi, xy, xz, yz = basis2lohi(basis)
    basis = matrix([[xhi, 0, 0], [xy, yhi, 0], [xz, yz, zhi]])

    N = sum(atypes)
    Ntypes = len(atypes)
    types = [i for i in flatten([[i] * v for i, v in enumerate(atypes)])]
    data = "#Generated by %s from %s\n\n" % (sys.argv[0].split("/")[-1], pcarFile)
    data += "%d atoms\n" % N
    data += "%d atom types\n\n" % Ntypes
    data += "0.0000  %4f  xlo xhi\n" % xhi
    data += "0.0000  %4f  ylo yhi\n" % yhi
    data += "0.0000  %4f  zlo zhi\n" % zhi
    data += "% 4f % 4f % 4f xy xz yz\n\n" % (xy, xz, yz)
    data += "Atoms\n\n"
    for i, (t, atom) in enumerate(zip(types, atoms)):
        x, y, z = atom  # (atom*basis).tolist()[0]
        data += "\t %d \t %d \t % 5f\t% 5f\t% 5f\n" % (i + 1, t + 1, x, y, z)
    lammps.write(data)
    lammps.close()
Ejemplo n.º 2
0
def poscar2dump(pcarFile, lmpFile, scale=None):
    try:
        poscar = open(pcarFile, "r").readlines()
        lammps = open(lmpFile, "w")
    except IOError:
        print "Error: %s Unable to open POSCAR/Lammps file." % sys.argv[
            0].split("/")[-1]
        usage()
        exit(0)

    if scale == None:
        scale = 1.0

    [basis, atypes, atoms, head, poscar] = poscarIO.read(poscar)

    #Convert from POSCAR style basis vectors to LAMMPS style boundaries.
    xhi, yhi, zhi, xy, xz, yz = basis2lohi(basis)
    basis = matrix([[xhi, 0, 0], [xy, yhi, 0], [xz, yz, zhi]])

    N = sum(atypes)
    Ntypes = len(atypes)
    types = [i for i in flatten([[i] * v for i, v in enumerate(atypes)])]
    data = "#Generated by %s from %s\n\n" % (sys.argv[0].split("/")[-1],
                                             pcarFile)
    data += "%d atoms\n" % N
    data += "%d atom types\n\n" % Ntypes
    data += "0.0000  %4f  xlo xhi\n" % xhi
    data += "0.0000  %4f  ylo yhi\n" % yhi
    data += "0.0000  %4f  zlo zhi\n" % zhi
    data += "% 4f % 4f % 4f xy xz yz\n\n" % (xy, xz, yz)
    data += "Atoms\n\n"
    for i, (t, atom) in enumerate(zip(types, atoms)):
        x, y, z = atom  #(atom*basis).tolist()[0]
        data += "\t %d \t %d \t % 5f\t% 5f\t% 5f\n" % (i + 1, t + 1, x, y, z)
    lammps.write(data)
    lammps.close()
Ejemplo n.º 3
0
three = range(3)
while True:
    mdcar.readline() #header
    mdcar.readline() #volume ratio
    v1 = map(float,mdcar.readline().split())
    v2 = map(float,mdcar.readline().split())
    v3 = map(float,mdcar.readline().split())

    nAtom = int(mdcar.readline())
    mdcar.readline() #direct
    atoms = [map(float,mdcar.readline().split()) for i in range(nAtom)]
    if len(atoms[nAtom-1])!=3:
        break
    types = [0 for i in range(nAtom)]

    xhi,yhi,zhi,xy,xz,yz = lammpsIO.basis2lohi([v1,v2,v3])
    bf=[xhi,yhi,zhi]
    atoms = [map(lambda x: (a[x]+0.5)*bf[x],three) for a in atoms]
    
    head= "ITEM: TIMESTEP\n%d\n"%count
    head+="ITEM: NUMBER OF ATOMS\n%d\n"%nAtom
    head+="ITEM: BOX BOUNDS\n"
    head+=" 0.0000  % 6.6f\n"%(xhi)
    head+=" 0.0000  % 6.6f\n"%(yhi)
    head+=" 0.0000  % 6.6f\n"%(zhi)
    head+="ITEM: ATOMS id type xs ys zs\n"
    opdat.write(head)

    atoms = zip(*atoms)
    opdat.writelines([" ".join(map(str,line))+"\n" for line in zip(range(nAtom),types,atoms[0],atoms[1],atoms[2])])