예제 #1
0
파일: vasp2fitpot.py 프로젝트: ryokbys/nap
def structure2aSys(structure,idoffset=1):
    """
    Converts Structure object of pymatgen to NAPSystem object in nap.

    Args:
        structure (Structure): pymatgen Structure object to be converted
        to NAPSystem object..

    Returns:
        aSys (NAPSystem): 
    """
    lattice= structure.lattice
    alc= 1.0
    a1= np.array(lattice.matrix[0])
    a2= np.array(lattice.matrix[1])
    a3= np.array(lattice.matrix[2])
    #... rescale a? vectors
    a1= a1/alc
    a2= a2/alc
    a3= a3/alc
    aSys= NAPSystem()
    aSys.set_lattice(alc,a1,a2,a3)
    for ia in range(structure.num_sites):
        ai= Atom()
        si= structure[ia]
        crd= si.frac_coords
        ai.set_pos(crd[0],crd[1],crd[2])
        sid= structure.symbol_set.index(si.species_string)+idoffset
        ai.set_sid(sid)
        ai.set_id(ia+1)
        aSys.add_atom(ai)
    return aSys
예제 #2
0
def xdatcar2poscars(fname='XDATCAR', nskip=1):
    f = open(fname, 'r')

    isys = 0
    while True:
        #....."Direct configuration= #"
        try:
            line = f.readline()
            #...Check configuration
            if not "Direct configuration=" in line:
                alc, a1, a2, a3, species, num_atoms = read_header(f)
                # print(species)
                # print(num_atoms)
                natm = 0
                for n in num_atoms:
                    natm += n
                continue
            elif len(line.split()) == 0:
                break
        except:
            break
        #...Skip reading this configuration if requested
        if not isys % nskip == 0:
            for i in range(natm):
                f.readline()
            isys += 1
            continue
        #...Following lines: atom positions
        #...Make a NAPSystem from these information and write to POSCAR_#####
        nsys = NAPSystem(specorder=species)
        nsys.set_lattice(alc, a1, a2, a3)
        inc = 0
        for inum, ni in enumerate(num_atoms):
            for j in range(ni):
                inc += 1
                ai = Atom()
                ai.set_id(inc)
                ai.set_symbol(species[inum])
                data = f.readline().split()
                # print(data)
                if not is_number(data[0]):
                    raise ValueError('Wrong format?')
                x1, x2, x3 = [float(x) for x in data[0:3]]
                ai.set_pos(x1, x2, x3)
                ai.set_vel(0.0, 0.0, 0.0)
                nsys.add_atom(ai)
        foutname = 'POSCAR_{0:05d}'.format(isys)
        print(' >>> ' + foutname)
        nsys.write_POSCAR(fname=foutname)
        isys += 1
    f.close()
    return None
예제 #3
0
파일: xdatcar.py 프로젝트: ryokbys/nap
def xdatcar2poscars(fname='XDATCAR',nskip=1):
    f= open(fname,'r')

    isys = 0
    while True:
        #....."Direct configuration= #"
        try:
            line = f.readline()
            #...Check configuration
            if not "Direct configuration=" in line:
                alc,a1,a2,a3,species,num_atoms = read_header(f)
                # print(species)
                # print(num_atoms)
                natm = 0
                for n in num_atoms:
                    natm += n
                continue
            elif len(line.split()) == 0:
                break
        except:
            break
        #...Skip reading this configuration if requested
        if not isys%nskip == 0:
            for i in range(natm):
                f.readline()
            isys += 1
            continue
        #...Following lines: atom positions
        #...Make a NAPSystem from these information and write to POSCAR_#####
        nsys = NAPSystem(specorder=species)
        nsys.set_lattice(alc,a1,a2,a3)
        inc = 0
        for inum,ni in enumerate(num_atoms):
            for j in range(ni):
                inc += 1
                ai = Atom()
                ai.set_id(inc)
                ai.set_symbol(species[inum])
                data= f.readline().split()
                # print(data)
                if not is_number(data[0]):
                    raise ValueError('Wrong format?')
                x1,x2,x3 = [ float(x) for x in data[0:3] ]
                ai.set_pos(x1,x2,x3)
                ai.set_vel(0.0,0.0,0.0)
                nsys.add_atom(ai)
        foutname = 'POSCAR_{0:05d}'.format(isys)
        print(' >>> '+foutname)
        nsys.write_POSCAR(fname=foutname)
        isys += 1
    f.close()
    return None