Beispiel #1
0
def gen2xyz(args):
    '''Converts the given INPUT file in DFTB+ GEN format to XYZ format.

    Args:
        args: Namespace of command line arguments
    '''
    infile = args.infile
    try:
        gen = Gen.fromfile(infile)
    except OSError:
        raise ScriptError('You must enter a valid path to the input file.')
    xyz = Xyz(gen.geometry, args.comment)
    if args.output:
        if args.output == "-":
            outfile = sys.stdout
        else:
            outfile = args.output
    else:
        if infile.endswith(".gen"):
            outfile = infile[:-4] + ".xyz"
        else:
            outfile = infile + ".xyz"
    xyz.tofile(outfile)

    if gen.geometry.periodic and args.lattfile:
        fp = open(args.lattfile, "w")
        for vec in gen.geometry.latvecs:
            fp.write("{0:18.10E} {1:18.10E} {2:18.10E}\n".format(*vec))
        fp.close()
Beispiel #2
0
def xyz_file_equals(current, reference, check_comment=False):
    '''Checks whether contents of an xyz file equals another one.

    Args:
        current (str): Name of xyz file to check.
        reference (str): Name of reference xyz file.
    '''
    curxyz = Xyz.fromfile(current)
    refxyz = Xyz.fromfile(reference)
    return curxyz.equals(refxyz, check_comment=check_comment)
Beispiel #3
0
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)