예제 #1
0
def main(argv=[]):
    args = getArgs(argv)
    
    atoms = read(args.file, format=args.format) if args.format else read(args.file)
    
    atoms = correct_z(atoms)
    atoms = fix_layers(atoms, args.fix, args.n_layers)
    
    kw = {'format': 'vasp', 'direct': True, 'vasp5': True, 'sort':True}
    write('POSCAR' + args.pad, atoms, **kw)
예제 #2
0
파일: convert.py 프로젝트: izxle/VaspTools
def main(argv=None):
    args = getArgs(argv)
    atoms = read(args.file, format=args.f) if args.f else struct = read(args.file)
    atoms = correct_z(atoms)
    kw = {"format": args.format}
    if args.format == 'vasp':
        kw['sort'] = True
        kw['vasp5'] = True
        kw['direct'] = True
    write(args.nam, atoms, **kw)
예제 #3
0
파일: slab.py 프로젝트: izxle/VaspTools
def main(argv=[]):
    args = getArgs(argv)
    # get slab
    atoms = read(args.slab) if args.slab else slab(args)
    # adjust cell
    atoms = correct_z(atoms)
    # set contraints
    if args.fix:
        atoms = fix_layers(atoms, args.fix, args.n_layers)
    # write POSCAR
    kw = {'format': 'vasp',
          'sort': True,
          'vasp5': True,
          'direct': True}
          
    nam = 'POSCAR' + args.pad
    write(nam, atoms, **kw)
예제 #4
0
파일: DOS.py 프로젝트: izxle/VaspTools
def get_args(args):
    parser = argparse.ArgumentParser(
                formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    
    parser.add_argument('directories', nargs='*', default=[getcwd()],
                        help='path to directories with DOS files to read')
    parser.add_argument('-n', nargs='+', default=[],
                        help='The index number of the atoms to be read')
    parser.add_argument('-e', nargs='+', default=[],
                        help='Read info of atoms of selected elements')
    parser.add_argument('-l', nargs='+', default=[], type=int,
                        help='Read info of atoms in selected layers')
    parser.add_argument('--e-range', nargs=2, default=[None, ''],
                        type=float, dest='e_range',
                        help='Range of energies for DOS calculations')
    parser.add_argument('--layers', type=int, default=4,
                        help='Number of layers in structure')
    parser.add_argument('--dbc', '--d-band-center', action='store_true',
                        default=False, dest='dbc',
                        help='get d-band center')
    parser.add_argument('-w', '--write', action='store_true', default=False,
                        help='write requested DOS data')
    parser.add_argument('-p', '-g', '--graph', '--plot', nargs='*',
                        choices=['s', 'p', 'd', 'f', 'sum'], dest='plot',
                        help='plot DOS for the specified orbitals')
    parser.add_argument('--name', default='DOSCAR',
                        help='name of DOSCAR file to read')
    parser.add_argument('-v', action='count', default=0)
    parser.add_argument('--test', action='store_true')

    res = parser.parse_args(args.split()) if args else parser.parse_args()
    
    if res.n:
        res.n = set(parse_int_set(res.n))
    
    if res.e_range[0]: res.e_range = [-1 * res.e_range[0], res.e_range[1]]
    
    n = {}
    for f in res.directories:
        nams = listdir(f)
        if res.name not in nams:
            print "Omitting directory '{}': No '{}' found.".format(f, res.name)
            res.directories.remove(f)
            continue
        indexes = res.n
        if res.l or res.e:
            for nam in ['CONTCAR', 'POSCAR', 'OUTCAR']:
                if nam in nams: break
            nam = path.join(f, nam)
            # read structure
            # TODO: read other formats?
            atoms = read(nam, format='vasp')
            indexes = res.n if res.n else set(xrange(1, len(atoms) + 1))
            if res.e:
                X_atoms = {a.index + 1 for a in atoms if a.symbol in res.e}
                indexes.intersection_update(X_atoms)
            if res.l:
                # adjust cell
                atoms = correct_z(atoms)
                # set layer tag to atoms
                atoms = tag_layers(atoms, res.layers)
                # get atoms in layers of interest
                atoms_in_layer = {a.index + 1 for a in atoms if a.tag in res.l}
                indexes.intersection_update(atoms_in_layer)
            if not indexes:
                contraints = []
                if res.n: contraints.append("n={}".format(res.n))
                if res.l: contraints.append("l={}".format(res.l))
                if res.e: contraints.append("e={}".format(res.e))
                msg = "{}\n".format(f) 
                msg += "    No atoms found within given constraints ("
                msg += ', '.join(contraints)
                msg += "), using all atoms."
        if res.v:
            print "{} atoms found with given constraints".format(len(indexes))
            print indexes if indexes else "  using all atoms"
        n[f] = list(indexes)
    res.n = n
    
    if res.plot == []:
        res.plot = ['s', 'p', 'd', 'sum']
    return res