def toReaxLammps(system, outfile="lammps.data"): """ output to lammps data file """ o = open(outfile, "w") o.write("# \n") o.write("\n") o.write("%d atoms\n\n" % len(system.atoms)) o.write("%d atom types\n\n" % len(system.map)) pbc = system.pbc if len(pbc) >= 6: if pbc[3] == 90.0 and pbc[4] == 90 and pbc[5] == 90: o.write(" 0.0 %12.7f xlo xhi\n" % pbc[0]) o.write(" 0.0 %12.7f ylo yhi\n" % pbc[1]) o.write(" 0.0 %12.7f zlo zhi\n" % pbc[2]) else: xx, xy, xz, yy, yz, zz = lattice2v(pbc) o.write(" 0.0 %12.7f xlo xhi\n" % xx) o.write(" 0.0 %12.7f ylo yhi\n" % yy) o.write(" 0.0 %12.7f zlo zhi\n" % zz) o.write("%12.7f%12.7f%12.7f xy xz yz\n\n" % (xy, xz, yz)) else: print "Warning: No box found. Using a default box 5.0 * 5.0 * 5.0" o.write(" %12.7f %12.7f xlo xhi\n" % (-25.0, 25.0)) o.write(" %12.7f %12.7f ylo yhi\n" % (-25.0, 25.0)) o.write(" %12.7f %12.7f zlo zhi\n" % (-25.0, 25.0)) o.write("Masses\n\n") for i in system.map: # atom name atn = "" for j in i[1]: if j.isdigit(): break atn += j o.write("%d %s # %s\n" % (i[0], ELEMENT2MASS[atn], atn)) o.write("\n") o.write("Atoms\n") o.write("\n") counter = 1 for i in system.atoms: line = "" line += "%-6d" % counter line += "%3d" % i.type1 line += "%10.6f" % i.charge line += "%16.9f" % i.x[0] line += "%16.9f" % i.x[1] line += "%16.9f" % i.x[2] line += "\n" o.write(line) counter += 1 o.close()
def toReaxLammps(system, outfile="lammps.data"): """ output to lammps data file """ o = open(outfile, 'w') o.write("# \n") o.write("\n") o.write("%d atoms\n\n" % len(system.atoms)) o.write("%d atom types\n\n" % len(system.map)) pbc = system.pbc if len(pbc) >= 6: if pbc[3] == 90.0 and pbc[4] == 90 and pbc[5] == 90: o.write(" 0.0 %12.7f xlo xhi\n" % pbc[0]) o.write(" 0.0 %12.7f ylo yhi\n" % pbc[1]) o.write(" 0.0 %12.7f zlo zhi\n" % pbc[2]) else: xx, xy, xz, yy, yz, zz = lattice2v(pbc) o.write(" 0.0 %12.7f xlo xhi\n" % xx) o.write(" 0.0 %12.7f ylo yhi\n" % yy) o.write(" 0.0 %12.7f zlo zhi\n" % zz) o.write("%12.7f%12.7f%12.7f xy xz yz\n\n" % (xy, xz, yz)) else: print("Warning: No box found. Using a default box 5.0 * 5.0 * 5.0") o.write(" %12.7f %12.7f xlo xhi\n" % (-25.0, 25.0)) o.write(" %12.7f %12.7f ylo yhi\n" % (-25.0, 25.0)) o.write(" %12.7f %12.7f zlo zhi\n" % (-25.0, 25.0)) o.write("Masses\n\n") for i in system.map: # atom name atn = '' for j in i[1]: if j.isdigit(): break atn += j o.write("%d %s # %s\n" % (i[0], ELEMENT2MASS[atn], atn)) o.write("\n") o.write("Atoms\n") o.write("\n") counter = 1 for i in system.atoms: line = '' line += "%-6d" % counter line += "%3d" % i.type1 line += "%10.6f" % i.charge line += "%16.9f" % i.x[0] line += "%16.9f" % i.x[1] line += "%16.9f" % i.x[2] line += "\n" o.write(line) counter += 1 o.close()
def toJdft(system, outfile="coords"): """Output the msd file """ s = system o = open(outfile, "w") xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) xx = xx * A2Bohr xy = xy * A2Bohr xz = xz * A2Bohr yy = yy * A2Bohr yz = yz * A2Bohr zz = zz * A2Bohr a = [xx, xy, xz] b = [0., yy, 0.] c = [0., 0., zz] o.write("lattice \\") o.write("\n") for i in a: o.write("%20.15f"%i) o.write("\\") o.write("\n") for i in b: o.write("%20.15f"%i) o.write("\\") o.write("\n") for i in c: o.write("%20.15f"%i) o.write("\n") o.write("\n") o.write("coords-type lattice\n") coords = [] coordsXr = [] natom = 0 for i in s.atoms: coords.append(np.array(i.xFrac)) coordsXr.append(i.xr) natom += 1 for i in range(natom): xf = coords[i][0] yf = coords[i][1] zf = coords[i][2] o.write("ion %2s %20.15f%20.15f%20.15f 0\n"%( s.atoms[i].element, xf, yf, zf)) o.write("\n") o.close()
def toCfg(system, outfile="out.cfg"): """Output the cfg file """ s = system o = open(outfile, "w") o.write("Number of particles = %d\n" % len(s.atoms)) o.write("A = 1.0 Angstrom (basic length-scale)\n") xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = [xx, 0.0, 0.0] b = [xy, yy, 0.0] c = [xz, yz, zz] o.write("H0(1,1) = %.4f A\n" % a[0]) o.write("H0(1,2) = %.4f A\n" % a[1]) o.write("H0(1,3) = %.4f A\n" % a[2]) o.write("H0(2,1) = %.4f A\n" % b[0]) o.write("H0(2,2) = %.4f A\n" % b[1]) o.write("H0(2,3) = %.4f A\n" % b[2]) o.write("H0(3,1) = %.4f A\n" % c[0]) o.write("H0(3,2) = %.4f A\n" % c[1]) o.write("H0(3,3) = %.4f A\n" % c[2]) o.write(".NO_VELOCITY.\n") o.write("entry_count = 3\n") elements = {} elements_list = [] # sort the coordinations according to element type for i in s.atoms: element = i.element if not element in elements.keys(): elements[element] = [] elements_list.append(element) elements[element].append(i) for i in elements_list: o.write("%d\n" % ELEMENT2ATN[i]) o.write("%s\n" % i) for j in elements[i]: xf = j.xFrac[0] yf = j.xFrac[1] zf = j.xFrac[2] o.write("%20.15f%20.15f%20.15f\n" % (xf, yf, zf)) o.close()
def toDump(system, outfile="output.dump"): """Output the dump file """ o = open(outfile, "w") o.write("ITEM: TIMESTEP\n") o.write("%d\n" % system.step) o.write("ITEM: NUMBER OF ATOMS\n") o.write("%d\n" % len(system.atoms)) # write the pbc pbc = system.pbc """ITEM: BOX BOUNDS xy xz yz xx yy zz xlo_bound xhi_bound xy ylo_bound yhi_bound xz zlo_bound zhi_bound yz """ if len(pbc) >= 6: if pbc[3] == 90.0 and pbc[4] == 90 and pbc[5] == 90: o.write("ITEM: BOX BOUNDS pp pp pp\n") o.write(" 0.0 %9.4f 0.0\n" % pbc[0]) o.write(" 0.0 %9.4f 0.0\n" % pbc[1]) o.write(" 0.0 %9.4f 0.0\n" % pbc[2]) else: o.write("ITEM: BOX BOUNDS xy xz yz pp pp pp\n") xx, xy, xz, yy, yz, zz = lattice2v(pbc) o.write(" %9.4f %9.4f %9.4f\n" % (xz, xx, xy)) o.write(" 0.0 %9.4f %9.4f\n" % (yy, xz)) o.write(" 0.0 %9.4f %9.4f\n" % (zz, yz)) else: print "Warning: No box found. Using a default box 5.0 * 5.0 * 5.0" o.write(" 0.0 %9.4f xlo xhi\n" % 5.0) o.write(" 0.0 %9.4f ylo yhi\n" % 5.0) o.write(" 0.0 %9.4f zlo zhi\n" % 5.0) o.write("ITEM: ATOMS id type x y z\n") for i in system.atoms: o.write("%-9d" % i.an) o.write("%6d" % i.type1) o.write("%14.6f" % i.x[0]) o.write("%14.6f" % i.x[1]) o.write("%14.6f" % i.x[2]) o.write("\n") o.close()
def toDump(system, outfile="output.dump"): """Output the dump file """ o = open(outfile, "w") o.write("ITEM: TIMESTEP\n") o.write("%d\n" % system.step) o.write("ITEM: NUMBER OF ATOMS\n") o.write("%d\n" % len(system.atoms)) # write the pbc pbc = system.pbc """ITEM: BOX BOUNDS xy xz yz xx yy zz xlo_bound xhi_bound xy ylo_bound yhi_bound xz zlo_bound zhi_bound yz """ if len(pbc) >= 6: if pbc[3] == 90.0 and pbc[4] == 90 and pbc[5] == 90: o.write("ITEM: BOX BOUNDS pp pp pp\n") o.write(" 0.0 %9.4f 0.0\n" % pbc[0]) o.write(" 0.0 %9.4f 0.0\n" % pbc[1]) o.write(" 0.0 %9.4f 0.0\n" % pbc[2]) else: o.write("ITEM: BOX BOUNDS xy xz yz pp pp pp\n") xx, xy, xz, yy, yz, zz = lattice2v(pbc) o.write(" %9.4f %9.4f %9.4f\n" % (xz, xx, xy)) o.write(" 0.0 %9.4f %9.4f\n" % (yy, xz)) o.write(" 0.0 %9.4f %9.4f\n" % (zz, yz)) else: print("Warning: No box found. Using a default box 5.0 * 5.0 * 5.0") o.write(" 0.0 %9.4f xlo xhi\n" % 5.0) o.write(" 0.0 %9.4f ylo yhi\n" % 5.0) o.write(" 0.0 %9.4f zlo zhi\n" % 5.0) o.write("ITEM: ATOMS id type x y z\n") for i in system.atoms: o.write("%-9d" % i.an) o.write("%6d" % i.type1) o.write("%14.6f" % i.x[0]) o.write("%14.6f" % i.x[1]) o.write("%14.6f" % i.x[2]) o.write("\n") o.close()
def gen_scan(s, args): start = 0.7 end = 1.3 start = np.power(start, 1/3.0) end = np.power(end, 1/3.0) n = 11 x = np.linspace(start, end, n) for i in range(n): folder = "scan_%02d"%i if not os.path.exists(folder): os.mkdir(folder) os.chdir(folder) shutil.copy("../INCAR", ".") shutil.copy("../POTCAR", ".") shutil.copy("../KPOINTS", ".") if os.path.exists('../pbs'): shutil.copy("../pbs", ".") s_new = copy.copy(s) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = np.array([xx, 0.0, 0.0]) b = np.array([xy, yy, 0.0]) c = np.array([xz, yz, zz]) if args.xyz: tmp = args.xyz[0] if tmp == "xy": a = a * x[i] b = b * x[i] elif tmp == "z": c = c * x[i] else: a = a * x[i] b = b * x[i] c = c * x[i] pbc = v2lattice(a, b, c) s_new.pbc = pbc toPoscar(s_new, "POSCAR") os.chdir("..")
def gen_scan(s, args): start = 0.8 end = 1.2 start = np.power(start, 1/3.0) end = np.power(end, 1/3.0) n = 11 x = np.linspace(start, end, n) for i in range(n): folder = "scan_%02d"%i if not os.path.exists(folder): os.mkdir(folder) os.chdir(folder) shutil.copy("../INCAR", ".") shutil.copy("../POTCAR", ".") shutil.copy("../KPOINTS", ".") shutil.copy("../pbs", ".") s_new = copy.copy(s) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = np.array([xx, 0.0, 0.0]) b = np.array([xy, yy, 0.0]) c = np.array([xz, yz, zz]) if args.xyz: tmp = args.xyz[0] if tmp == "xy": a = a * x[i] b = b * x[i] elif tmp == "z": c = c * x[i] else: a = a * x[i] b = b * x[i] c = c * x[i] pbc = v2lattice(a, b, c) s_new.pbc = pbc toPoscar(s_new, "POSCAR") os.chdir("..")
def toFullLammps(system, outfile="output.data"): """ output to lammps data file in full format """ s = system o = open(outfile, "w") o.write("# \n") o.write("\n") o.write("%d atoms\n" % s.n_atoms) o.write("%d bonds\n" % s.n_bonds) o.write("%d angles\n" % s.n_angles) o.write("%d dihedrals\n" % s.n_dihedrals) o.write("%d impropers\n\n" % s.n_impropers) o.write("%d atom types\n" % s.n_atomtypes) o.write("%d bond types\n" % s.n_bondtypes) o.write("%d angle types\n" % s.n_angletypes) o.write("%d dihedral types\n" % s.n_dihedraltypes) o.write("%d improper types\n\n" % s.n_impropertypes) pbc = s.pbc if len(pbc) >= 6: if pbc[3] == 90.0 and pbc[4] == 90 and pbc[5] == 90: o.write(" %12.4f %12.4f xlo xhi\n" % (0.0, pbc[0])) o.write(" %12.4f %12.4f ylo yhi\n" % (0.0, pbc[1])) o.write(" %12.4f %12.4f zlo zhi\n" % (0.0, pbc[2])) else: xx, xy, xz, yy, yz, zz = lattice2v(pbc) o.write(" %12.4 %12.4f xlo xhi\n" % (0.0, xx)) o.write(" %12.4 %12.4f ylo yhi\n" % (0.0, yy)) o.write(" %12.4 %12.4f zlo zhi\n" % (0.0, zz)) o.write("%12.4f%12.4f%12.4f xy xz yz\n\n" % (xy, xz, yz)) else: print "Warning: No box found. Using a default box 5.0 * 5.0 * 5.0" o.write(" %9.4f %9.4f xlo xhi\n" % (-25.0, 25.0)) o.write(" %9.4f %9.4f ylo yhi\n" % (-25.0, 25.0)) o.write(" %9.4f %9.4f zlo zhi\n" % (-25.0, 25.0)) o.write("\nMasses\n\n") counter = 1 for i in s.atomtypes: # atom name na = counter ele = s.atomtypes[na - 1] o.write("%12d %12s # %s\n" % (na, ELEMENT2MASS[ele], ele)) counter += 1 o.write("\n") o.write("Atoms\n") o.write("\n") counter = 1 for i in s.atoms: line = "" line += "%12d" % counter line += "%12d" % i.resn line += "%6d" % i.type2 line += "%12.6f" % i.charge line += "%12.6f" % i.x[0] line += "%12.6f" % i.x[1] line += "%12.6f" % i.x[2] line += " # " line += "%6s" % i.name line += "\n" o.write(line) counter += 1 counter = 1 if s.n_bonds > 0: o.write("\nBonds\n\n") for i in s.bonds: o.write("%12d" % counter) o.write("%12d" % i[1]) o.write("%12d" % i[2]) o.write("%12d" % i[3]) o.write("\n") counter += 1 counter = 1 if s.n_angles > 0: o.write("\nAngles\n\n") for i in s.angles: o.write("%12d" % counter) o.write("%12d" % i[1]) o.write("%12d" % i[2]) o.write("%12d" % i[3]) o.write("%12d" % i[4]) o.write("\n") counter += 1 counter = 1 if s.n_dihedrals > 0: o.write("\nDihedrals\n\n") for i in s.dihedrals: o.write("%12d" % counter) o.write("%12d" % i[1]) o.write("%12d" % i[2]) o.write("%12d" % i[3]) o.write("%12d" % i[4]) o.write("%12d" % i[5]) o.write("\n") counter += 1 if len(s.ffparams) > 0: o.write("\n") for i in s.ffparams: o.write(i) o.write("\n") o.close()
def toPoscar(system, outfile="POSCAR"): """Output the POSCAR file """ s = system o = open(outfile, "w") o.write("%s\n" % s.name) o.write("%20.15f\n" % s.scaleFactor) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = [xx, 0.0, 0.0] b = [xy, yy, 0.0] c = [xz, yz, zz] # write the cells for i in a: o.write("%20.15f" % i) o.write("\n") for i in b: o.write("%20.15f" % i) o.write("\n") for i in c: o.write("%20.15f" % i) o.write("\n") elements = {} elements_list = [] # sort the coordinations according to element type for i in s.atoms: element = i.element if not element in elements.keys(): elements[element] = [] elements_list.append(element) elements[element].append(i) for i in elements_list: o.write("%6s" % i) o.write("\n") for i in elements_list: o.write("%6d" % len(elements[i])) o.write("\n") o.write("Selective dynamics\n") o.write("Direct\n") coords = [] coordsXr = [] natom = 0 for i in elements_list: for j in elements[i]: coords.append(np.array(j.xFrac)) coordsXr.append(j.xr) natom += 1 for i in range(natom): xf = coords[i][0] yf = coords[i][1] zf = coords[i][2] o.write("%20.15f%20.15f%20.15f" % (xf, yf, zf)) xr = "T" yr = "T" zr = "T" if coordsXr[i][0] == 1: xr = "F" if coordsXr[i][1] == 1: yr = "F" if coordsXr[i][2] == 1: zr = "F" o.write("%4s%4s%4s\n" % (xr, yr, zr)) o.write("\n") o.close()
def toPoscar(system, outfile="POSCAR"): """Output the msd file """ s = system o = open(outfile, "w") o.write("%s\n"%s.name) o.write("%20.15f\n"%s.scaleFactor) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = [xx, 0.0, 0.0] b = [xy, yy, 0.0] c = [xz, yz, zz] """ latvecs = np.array([a, b, c], dtype=float) invlatvecs = np.linalg.inv(latvecs) [xf, yf, zf] = np.dot(coords[i], invlatvecs) """ # write the cells for i in a: o.write("%20.15f"%i) o.write("\n") for i in b: o.write("%20.15f"%i) o.write("\n") for i in c: o.write("%20.15f"%i) o.write("\n") for i in s.atomtypes: o.write("%6s"%i) o.write("\n") for i in s.natoms: o.write("%6d"%i) o.write("\n") o.write("Selective dynamics\n") o.write("Direct\n") coords = [] coordsXr = [] natom = 0 for i in s.atoms: coords.append(np.array(i.xFrac)) coordsXr.append(i.xr) natom += 1 for i in range(natom): xf = coords[i][0] yf = coords[i][1] zf = coords[i][2] o.write("%20.15f%20.15f%20.15f"%(xf, yf, zf)) xr = "T" yr = "T" zr = "T" if coordsXr[i][0] == 1: xr = "F" if coordsXr[i][1] == 1: yr = "F" if coordsXr[i][2] == 1: zr = "F" o.write("%4s%4s%4s\n"%(xr, yr, zr)) o.write("\n") o.close()
def toFullLammps(system, outfile="output.data"): """ output to lammps data file in full format """ s = system o = open(outfile, 'w') o.write("# \n") o.write("\n") o.write("%d atoms\n" % s.n_atoms) o.write("%d bonds\n" % s.n_bonds) o.write("%d angles\n" % s.n_angles) o.write("%d dihedrals\n" % s.n_dihedrals) o.write("%d impropers\n\n" % s.n_impropers) o.write("%d atom types\n" % s.n_atomtypes) o.write("%d bond types\n" % s.n_bondtypes) o.write("%d angle types\n" % s.n_angletypes) o.write("%d dihedral types\n" % s.n_dihedraltypes) o.write("%d improper types\n\n" % s.n_impropertypes) pbc = s.pbc if len(pbc) >= 6: if pbc[3] == 90.0 and pbc[4] == 90 and pbc[5] == 90: o.write(" %12.4f %12.4f xlo xhi\n" % (0.0, pbc[0])) o.write(" %12.4f %12.4f ylo yhi\n" % (0.0, pbc[1])) o.write(" %12.4f %12.4f zlo zhi\n" % (0.0, pbc[2])) else: xx, xy, xz, yy, yz, zz = lattice2v(pbc) o.write(" %12.4 %12.4f xlo xhi\n" % (0.0, xx)) o.write(" %12.4 %12.4f ylo yhi\n" % (0.0, yy)) o.write(" %12.4 %12.4f zlo zhi\n" % (0.0, zz)) o.write("%12.4f%12.4f%12.4f xy xz yz\n\n" % (xy, xz, yz)) else: print("Warning: No box found. Using a default box 5.0 * 5.0 * 5.0") o.write(" %9.4f %9.4f xlo xhi\n" % (-25.0, 25.0)) o.write(" %9.4f %9.4f ylo yhi\n" % (-25.0, 25.0)) o.write(" %9.4f %9.4f zlo zhi\n" % (-25.0, 25.0)) o.write("\nMasses\n\n") counter = 1 for i in s.atomtypes: # atom name na = counter ele = s.atomtypes[na - 1] o.write("%12d %12s # %s\n" % (na, ELEMENT2MASS[ele], ele)) counter += 1 o.write("\n") o.write("Atoms\n") o.write("\n") counter = 1 for i in s.atoms: line = '' line += "%12d" % counter line += "%12d" % i.resn line += "%6d" % i.type2 line += "%12.6f" % i.charge line += "%12.6f" % i.x[0] line += "%12.6f" % i.x[1] line += "%12.6f" % i.x[2] line += " # " line += "%6s" % i.name line += "\n" o.write(line) counter += 1 counter = 1 if s.n_bonds > 0: o.write("\nBonds\n\n") for i in s.bonds: o.write("%12d" % counter) o.write("%12d" % i[1]) o.write("%12d" % i[2]) o.write("%12d" % i[3]) o.write("\n") counter += 1 counter = 1 if s.n_angles > 0: o.write("\nAngles\n\n") for i in s.angles: o.write("%12d" % counter) o.write("%12d" % i[1]) o.write("%12d" % i[2]) o.write("%12d" % i[3]) o.write("%12d" % i[4]) o.write("\n") counter += 1 counter = 1 if s.n_dihedrals > 0: o.write("\nDihedrals\n\n") for i in s.dihedrals: o.write("%12d" % counter) o.write("%12d" % i[1]) o.write("%12d" % i[2]) o.write("%12d" % i[3]) o.write("%12d" % i[4]) o.write("%12d" % i[5]) o.write("\n") counter += 1 if len(s.ffparams) > 0: o.write("\n") for i in s.ffparams: o.write(i) o.write("\n") o.close()
def toJdft(system, outfile="coords"): """Output the Jdft file """ s = system o = open(outfile, "w") xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) xx = xx * A2Bohr xy = xy * A2Bohr xz = xz * A2Bohr yy = yy * A2Bohr yz = yz * A2Bohr zz = zz * A2Bohr a = [xx, xy, xz] b = [0., yy, 0.] c = [0., 0., zz] o.write("lattice \\") o.write("\n") for i in a: o.write("%20.15f" % i) o.write("\\") o.write("\n") for i in b: o.write("%20.15f" % i) o.write("\\") o.write("\n") for i in c: o.write("%20.15f" % i) o.write("\n") o.write("\n") o.write("coords-type lattice\n") coords = [] coordsXr = [] natom = 0 for i in s.atoms: coords.append(np.array(i.xFrac)) coordsXr.append(i.xr) natom += 1 for i in range(natom): xf = coords[i][0] yf = coords[i][1] zf = coords[i][2] o.write("ion %2s %20.15f%20.15f%20.15f 0\n" % (s.atoms[i].element, xf, yf, zf)) o.write("\n") o.close() o = open(outfile + "_cartesian", "w") o.write("lattice \\") o.write("\n") for i in a: o.write("%20.15f" % i) o.write("\\") o.write("\n") for i in b: o.write("%20.15f" % i) o.write("\\") o.write("\n") for i in c: o.write("%20.15f" % i) o.write("\n") o.write("\n") o.write("coords-type cartesian\n") coords = [] coordsXr = [] natom = 0 for i in s.atoms: coords.append(np.array(i.x)) coordsXr.append(i.xr) natom += 1 for i in range(natom): x = coords[i][0] * A2Bohr y = coords[i][1] * A2Bohr z = coords[i][2] * A2Bohr o.write("ion %2s %20.15f%20.15f%20.15f 0\n" % (s.atoms[i].element, x, y, z)) o.write("\n") o.close()
def toPoscar(system, outfile="POSCAR"): """Output the POSCAR file """ ndxfile = 'index.ndx' s = system o = open(outfile, "w") ndx = open(ndxfile, 'w') ndx.write('# original-id new-id\n') o.write("%s\n" % s.name) o.write("%20.15f\n" % s.scaleFactor) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = [xx, 0.0, 0.0] b = [xy, yy, 0.0] c = [xz, yz, zz] # write the cells for i in a: o.write("%20.15f" % i) o.write("\n") for i in b: o.write("%20.15f" % i) o.write("\n") for i in c: o.write("%20.15f" % i) o.write("\n") elements = {} elements_list = [] # sort the coordinations according to element type for i in s.atoms: element = i.element if not element in elements.keys(): elements[element] = [] elements_list.append(element) elements[element].append(i) for i in elements_list: o.write("%6s" % i) o.write("\n") for i in elements_list: o.write("%6d" % len(elements[i])) o.write("\n") o.write("Selective dynamics\n") o.write("Direct\n") coords = [] coordsXr = [] id_numbers = [] natom = 0 for i in elements_list: for j in elements[i]: coords.append(np.array(j.xFrac)) coordsXr.append(j.xr) id_numbers.append(j.number) natom += 1 for i in range(natom): ndx.write('%d %d\n' % (i + 1, id_numbers[i])) xf = coords[i][0] yf = coords[i][1] zf = coords[i][2] o.write("%20.15f%20.15f%20.15f" % (xf, yf, zf)) xr = "T" yr = "T" zr = "T" if coordsXr[i][0] == 1: xr = "F" if coordsXr[i][1] == 1: yr = "F" if coordsXr[i][2] == 1: zr = "F" o.write("%4s%4s%4s\n" % (xr, yr, zr)) o.write("\n") ndx.close() o.close()
1 2 improper 0 """ if len(sys.argv) > 2: nmol = int(sys.argv[2]) a = Pdb(sys.argv[1]) b = a.parser() b.assignAtomTypes() b.assignEleTypes() toTowheecoords(b) rcut = 3.5 xx, xy, xz, yy, yz, zz = lattice2v(b.pbc) la = [xx, 0.0, 0.0] lb = [xy, yy, 0.0] lc = [xz, yz, zz] print la print lb print lc o = open("towhee_input", "w") o.write("inputformat\n") o.write("'Towhee'\n") o.write("ensemble\n") o.write("'uvt'\n") o.write("temperature\n") o.write("256.0d0\n") o.write("nmolty\n")