コード例 #1
0
ファイル: io.py プロジェクト: xusg0915/CASMcode
def write_vasp_input(dirpath,
                     incarfile,
                     prim_kpointsfile,
                     prim_poscarfile,
                     super_poscarfile,
                     speciesfile,
                     sort=True,
                     extra_input_files=[],
                     strict_kpoints=False):
    """ Write VASP input files in directory 'dirpath' """
    print "Setting up VASP input files:", dirpath

    # read prim and prim kpoints
    print "  Reading KPOINTS:", prim_kpointsfile
    prim_kpoints = kpoints.Kpoints(prim_kpointsfile)
    if prim_poscarfile != None:
        print "  Reading KPOINTS reference POSCAR:", prim_poscarfile
        prim = poscar.Poscar(prim_poscarfile)
    else:
        prim = None

    # read species, super poscar, incar, and generate super kpoints
    print "  Reading SPECIES:", speciesfile
    species_settings = species.species_settings(speciesfile)
    print "  Reading supercell POS:", super_poscarfile
    super = poscar.Poscar(super_poscarfile, species_settings)
    print "  Reading INCAR:", incarfile
    super_incar = incar.Incar(incarfile, species_settings, super, sort)
    print "  Generating supercell KPOINTS"
    if strict_kpoints:
        super_kpoints = prim_kpoints
    else:
        super_kpoints = prim_kpoints.super_kpoints(prim, super)

    # write main input files
    print "  Writing supercell POSCAR:", os.path.join(dirpath, 'POSCAR')
    super.write(os.path.join(dirpath, 'POSCAR'), sort)
    print "  Writing INCAR:", os.path.join(dirpath, 'INCAR')
    super_incar.write(os.path.join(dirpath, 'INCAR'))
    print "  Writing supercell KPOINTS:", os.path.join(dirpath, 'KPOINTS')
    super_kpoints.write(os.path.join(dirpath, 'KPOINTS'))
    print "  Writing POTCAR:", os.path.join(dirpath, 'POTCAR')
    write_potcar(os.path.join(dirpath, 'POTCAR'), super, species_settings,
                 sort)

    # copy extra input files
    if len(extra_input_files):
        print "  Copying extra input files",
    for s in extra_input_files:
        print "    ", s
        shutil.copy(s, dirpath)

    print "  DONE\n"
    sys.stdout.flush()
コード例 #2
0
def write_quantum_espresso_input(dirpath,
                                 infilename,
                                 super_poscarfile,
                                 speciesfile,
                                 sort=True,
                                 extra_input_files=[],
                                 strict_kpoints=False):
    """ Write Quantum Espresso input files in directory 'dirpath' """
    print "Setting up Quantum Espresso input files:", dirpath

    # read Infile for K_POINTS, CELL_PARAMETERS, and generate super kpoints
    print "  Reading Infile:", infilename
    myinfile = infile.Infile(infilename, None, None, sort)
    print "  Reading SPECIES:", speciesfile
    species_settings = species.species_settings(speciesfile)
    print "  Reading K_POINTS from:", infilename
    prim_kpoints = myinfile.cards["K_POINTS"]
    print "  Reading K_POINTS reference positions from CELL_PARAMETERS:", infilename
    prim = poscar.Poscar(infilename, species_settings)
    print "  Reading supercell POS:", super_poscarfile
    super = poscar.Poscar(super_poscarfile, species_settings)
    print "  Generating supercell KPOINTS"
    if strict_kpoints:
        super_kpoints = prim_kpoints
    else:
        super_kpoints = prim_kpoints.super_kpoints(prim, super)

    #get raw infile name (without directories)
    directories = re.split("/", infilename)
    if len(directories) > 1:
        infilename = directories[-1]

    # write main input file
    print "  Writing supercell positions to Infile"
    myinfile.rewrite_poscar_info(super)
    print "  Writing supercell K_POINTS to Infile"
    myinfile.cards["K_POINTS"] = super_kpoints
    print "  Writing Infile:", os.path.join(dirpath, infilename)
    myinfile.write(os.path.join(dirpath, infilename))

    # copy extra input files
    print "  Copying extra input files",
    for s in extra_input_files:
        print s,
        shutil.copy(s, dirpath)
    print ""

    print "Quantum Espresso input files complete\n"
    sys.stdout.flush()
コード例 #3
0
 def __init__(self, incarfile, prim_kpointsfile, prim_poscarfile, super_poscarfile, speciesfile, sort=False):
     """ Construct a VaspIO object
        
         Args:
             incarfile:  path to INCAR file
             prim_kpointsfile: path to primitive KPOINTS file
             prim_poscarfile: path to primitive POSCAR file
             super_poscarfile: path to POSCAR file for this configuration
             speciesfile: path to SPECIES file
          
         This functions reads the input files and generates self.kpoints appropriate for self.poscar 
         given that 'prim_kpointsfile' is for 'prim_poscarfile'.
     """
     prim = poscar.Poscar(prim_poscarfile)
     prim_kpoints = kpoints.Kpoints(prim_kpointsfile)
     
     
     self.species = species.species_settings(speciesfile)
     self.poscar = poscar.Poscar(super_poscarfile, self.species)
     self.incar = incar.Incar(incarfile, self.species, self.poscar, sort)
     self.kpoints = prim_kpoints.super_kpoints(prim, self.poscar)
コード例 #4
0
#!/usr/bin/python
import sys
import io
import os
import logging
import numpy as np
testdir = os.path.dirname(__file__)
srcdir = '../parsevasp'
sys.path.insert(0, os.path.abspath(os.path.join(testdir, srcdir)))
import poscar

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('Testing')

poscar = poscar.Poscar(file_path = testdir + "/POSCAREXT")

poscar.modify("unitcell", np.array([[2.0, 0.0, 0.0],
                                 [0.0, 2.0, 0.0],
                                 [0.0, 0.0, 2.0]]))
poscar.delete_site(2)

poscar.write(file_path = testdir + "/POSCAREXTMOD")
コード例 #5
0
    def iter_read(self):
        """ Create a QErun object from an  outfile """
        myoutfile = outfile.Outfile(self.outfilename)
        pos = poscar.Poscar(self.outfilename)
        self.is_complete = myoutfile.complete
        self.all_e_0 = myoutfile.E
        self.total_energy = self.all_e_0[-1]
        self.lattice = pos._lattice.tolist()
        self.rec_lat = pos._reciprocal_lattice
        self.coord_mode = pos.coord_mode
        self.atom_type = pos.type_atoms
        self.atoms_per_type = pos.num_atoms
        self.elec_conv = True 
        
        ###Read things that haven't been taken care of by other functions
        ### i.e. efermi, dos_lm, Band, DOS, dos, forces, nstep
        if os.path.isfile(self.outfilename):
            if self.outfilename.split(".")[-1].lower() == "gz":
                f = gzip.open(self.outfilename)
            else:
                f = open(self.outfilename)
        elif os.path.isfile(self.outfilename+".gz"):
            f = gzip.open(self.outfilename+".gz")
        else:
            raise QErunError("file not found: " + self.outfilename)

        line=f.readline()
        m = re.search("Final en.*",line)
        while not m and self.elec_conv:
               line = f.readline()
               if line=='':
                    self.elec_conv = False
               line = line.strip()
               m = re.search("Final en.*",line)
        f.seek(0)
        
        line=f.readline()
        m = re.search("highest occupied level.*",line)
        if not m:
            while not m:
               line = f.readline()
               if line=='':
                    raise QErunError("EOF reach without finding highest occupied level")
               line = line.strip()
               m = re.search("highest occupied level.*",line)
        try:
            self.efermi = float(line.split()[-1])
        except ValueError:
            raise QErunError("could not convert efermi to float")

        line=f.readline()
        m = re.search("Forces acting on atoms.*",line)
        if not m:
            while not m:
               line = f.readline()
               if line=='':
                    raise QErunError("EOF reach without finding Forces acting on atoms")
               line = line.strip()
               m = re.search("Forces acting on atoms.*",line)
        forces=[]
        f.readline()
        for i in range(sum(self.atoms_per_type)):
            line=f.readline().split()
            forces+=[[float(line[-3]),float(line[-2]),float(line[-1])]]
        
        f.close()
        #Band & DOS stuff not implemented

        #parse basis from poscar object into 2d list
        names=[]
        for site in pos.basis:
            names+= [site.occ_alias]
        sortednames=sorted(names,key=lambda x: self.atom_type.index(x))
        indexmap=sorted(range(len(names)),key=lambda x: sortednames.index(names[x]))
        rawlist=[]
        for site in pos.basis:
            rawlist += [site.position]
        #make sure basis and forces correspond
        self.basis = map(lambda x:rawlist[x].tolist() ,indexmap)

        self.forces = map(lambda x:forces[x] ,indexmap)