def xyz2gen(args): '''Converts the given INPUT file in XYZ format to DFTB+ GEN format. Args: args: Namespace of command line arguments ''' infile = args.infile try: xyz = Xyz.fromfile(infile) except OSError: raise ScriptError('You must enter a valid path to the input file.') geo = xyz.geometry if args.lattfile: fp = open(args.lattfile, "r") tmp = np.fromfile(fp, count=9, dtype=float, sep=" ") latvecs = tmp.reshape((3, 3)) fp.close() geo.setlattice(latvecs) gen = Gen(geo, fractional=args.fractional) if args.output: if args.output == "-": outfile = sys.stdout else: outfile = args.output else: if infile.endswith(".xyz"): outfile = infile[:-4] + ".gen" else: outfile = infile + ".gen" gen.tofile(outfile)
def repeatgen(infile, repeats, options): '''Repeats geometry from gen files. Args: infile: File containing the gen-formatted geometry. repeats: (n1, n2, n3) integer tuple containing the repetitions along each lattice vector. options: Options (e.g. as returned by the command line parser). ''' gen = Gen.fromfile(infile) geo = gen.geometry latvecs = geo.latvecs if options.latticefile: latvecs = np.fromfile(options.latticefile, sep=' ') if len(latvecs) != 9: msg = ('Invalid number of lattice vector components in ' + options.latticefile) raise ScriptError(msg) latvecs.shape = (3, 3) if latvecs is None: msg = 'No lattice vectors found (neither in gen nor in external file)' raise ScriptError(msg) newgeo = _repeatgeo(geo, latvecs, repeats) newgen = Gen(newgeo, gen.fractional) outfile = options.output if outfile == '-': outfile = sys.stdout newgen.tofile(outfile)
def straingen(args, strain): '''Strains a geometry from a gen file. Args: args: Namespace of command line arguments strain: Strain to apply ''' infile = args.infile try: gen = Gen.fromfile(infile) except OSError: raise ScriptError('You must enter a valid path to the input file.') geometry = gen.geometry strainmtx = np.zeros((3, 3), dtype=float) for jj in range(3): strainmtx[jj][jj] = 1.0 components = LABELS[args.component.lower()] for ii in components: strainmtx[VOIGHT[ii][0]][VOIGHT[ii][1]] += 0.005 * strain strainmtx[VOIGHT[ii][1]][VOIGHT[ii][0]] += 0.005 * strain if geometry.latvecs is not None: geometry.latvecs = np.dot(geometry.latvecs, strainmtx) geometry.coords = np.dot(geometry.coords, strainmtx) if args.output: if args.output == "-": outfile = sys.stdout else: outfile = args.output else: if infile.endswith(".gen"): outfile = infile else: outfile = infile + ".gen" gen = Gen(geometry, fractional=gen.fractional) gen.tofile(outfile)
def straingen(infile, strain, options): '''Strains a geometry from a gen file. Args: infile: File containing the gen-formatted geometry strain: Strain to apply options: Options (e.g. as returned by the command line parser) ''' gen = Gen.fromfile(infile) geometry = gen.geometry strainmtx = np.zeros((3, 3), dtype=float) for jj in range(3): strainmtx[jj][jj] = 1.0 components = LABELS[options.component.lower()] for ii in components: strainmtx[VOIGHT[ii][0]][VOIGHT[ii][1]] += 0.005 * strain strainmtx[VOIGHT[ii][1]][VOIGHT[ii][0]] += 0.005 * strain if geometry.latvecs is not None: geometry.latvecs = np.dot(geometry.latvecs, strainmtx) geometry.coords = np.dot(geometry.coords, strainmtx) if options.output: if options.output == "-": outfile = sys.stdout else: outfile = options.output else: if infile.endswith(".gen"): outfile = infile else: outfile = infile + ".gen" gen = Gen(geometry, fractional=gen.fractional) gen.tofile(outfile)
def repeatgen(args): '''Repeats geometry from gen files. Args: args: Namespace of command line arguments ''' infile = args.infile repeats = [args.n1, args.n2, args.n3] try: gen = Gen.fromfile(infile) except OSError: raise ScriptError('You must enter a valid path to the input file.') geo = gen.geometry latvecs = geo.latvecs if args.latticefile: latvecs = np.fromfile(args.latticefile, sep=' ') if len(latvecs) != 9: msg = ('Invalid number of lattice vector components in ' + args.latticefile) raise ScriptError(msg) latvecs.shape = (3, 3) if latvecs is None: msg = 'No lattice vectors found (neither in gen nor in external file)' raise ScriptError(msg) if args.phonons: newgeo = _repeatgeo2(geo, latvecs, repeats) else: newgeo = _repeatgeo(geo, latvecs, repeats) newgen = Gen(newgeo, gen.fractional) outfile = args.output if outfile == '-': outfile = sys.stdout newgen.tofile(outfile)