def write_xyz(filename, obj, name='pwtools_dummy_mol_name'): """Write VMD-style [VMD] XYZ file. length: Angstrom Parameters ---------- filename : target file name obj : Trajectory or Structure name : str, optional Molecule name. References ---------- [VMD] http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/xyzplugin.html """ traj = crys.struct2traj(obj) xyz_str = "" for istep in range(traj.nstep): xyz_str += "%i\n%s\n%s" %(traj.natoms, name + '.%i' %(istep + 1), pwscf.atpos_str_fast(traj.symbols, traj.coords[istep,...]), ) common.file_write(filename, xyz_str)
def write_xyz(filename, obj, name='pwtools_dummy_mol_name'): """Write VMD-style [VMD] XYZ file. length: Angstrom Parameters ---------- filename : target file name obj : Trajectory or Structure name : str, optional Molecule name. References ---------- [VMD] http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/xyzplugin.html """ traj = crys.struct2traj(obj) xyz_str = "" for istep in range(traj.nstep): xyz_str += "%i\n%s\n%s" % ( traj.natoms, name + '.%i' % (istep + 1), pwscf.atpos_str_fast(traj.symbols, traj.coords[istep, ...]), ) common.file_write(filename, xyz_str)
def write_axsf(filename, obj): """Write animated XSF file for Structure (only 1 step) or Trajectory. Note that forces are converted eV / Ang -> Ha / Ang. length: Angstrom forces: Ha / Angstrom Parameters ---------- filename : target file name obj : Structure or Trajectory References ---------- [XSF] http://www.xcrysden.org/doc/XSF.html """ # Notes # ----- # XSF: The XSF spec [XSF] is a little fuzzy about what PRIMCOORD actually # is (fractional or cartesian Angstrom). Only the latter case results # in a correctly displayed structure in xcrsyden. So we use that. # # Speed: The only time-consuming step is calling atpos_str*() in the loop # b/c that transforms *every* single float to a string, which # effectively is a double loop over `ccf`. No way to get faster w/ pure # Python. # traj = crys.struct2traj(obj) # ccf = cartesian coords + forces (6 columns) if traj.is_set_attr('forces'): ccf = np.concatenate((traj.coords, traj.forces*eV/Ha), axis=-1) else: ccf = traj.coords axsf_str = "ANIMSTEPS %i\nCRYSTAL" %traj.nstep for istep in range(traj.nstep): axsf_str += "\nPRIMVEC %i\n%s" %(istep+1, common.str_arr(traj.cell[istep,...])) axsf_str += "\nPRIMCOORD %i\n%i 1\n%s" %(istep+1, traj.natoms, pwscf.atpos_str_fast(traj.symbols, ccf[istep,...])) common.file_write(filename, axsf_str)
def write_axsf(filename, obj): """Write animated XSF file for Structure (only 1 step) or Trajectory. Note that forces are converted eV / Ang -> Ha / Ang. length: Angstrom forces: Ha / Angstrom Parameters ---------- filename : target file name obj : Structure or Trajectory References ---------- [XSF] http://www.xcrysden.org/doc/XSF.html """ # Notes # ----- # XSF: The XSF spec [XSF] is a little fuzzy about what PRIMCOORD actually # is (fractional or cartesian Angstrom). Only the latter case results # in a correctly displayed structure in xcrsyden. So we use that. # # Speed: The only time-consuming step is calling atpos_str*() in the loop # b/c that transforms *every* single float to a string, which # effectively is a double loop over `ccf`. No way to get faster w/ pure # Python. # traj = crys.struct2traj(obj) # ccf = cartesian coords + forces (6 columns) if traj.is_set_attr('forces'): ccf = np.concatenate((traj.coords, traj.forces * eV / Ha), axis=-1) else: ccf = traj.coords axsf_str = "ANIMSTEPS %i\nCRYSTAL" % traj.nstep for istep in range(traj.nstep): axsf_str += "\nPRIMVEC %i\n%s" % ( istep + 1, common.str_arr(traj.cell[istep, ...])) axsf_str += "\nPRIMCOORD %i\n%i 1\n%s" % ( istep + 1, traj.natoms, pwscf.atpos_str_fast(traj.symbols, ccf[istep, ...])) common.file_write(filename, axsf_str)