Beispiel #1
0
    def __init__(self,
                 incarfile,
                 ref_kpointsfile,
                 ref_structurefile,
                 structurefile,
                 speciesfile,
                 sort=False):
        """ Construct a VaspIO object

            Args:
                incarfile:  path to INCAR file
                ref_kpointsfile: path to a reference KPOINTS file
                ref_structurefile: path to a reference CASM structure.json or VASP POSCAR file, used for scaling k-points
                structurefile: path to CASM structure.json or VASP POSCAR file
                    for the configuration
                speciesfile: path to SPECIES file

            This functions reads the input files and generates self.kpoints appropriate for self.poscar given that 'ref_kpointsfile' is for 'ref_structurefile'.
        """
        ref_structure = poscar.Poscar(ref_structurefile)
        ref_kpoints = kpoints.Kpoints(ref_kpointsfile)

        self.species = species.species_settings(speciesfile)
        self.poscar = poscar.Poscar(structurefile, self.species)
        self.incar = incar.Incar(incarfile, self.species, self.poscar, sort)
        self.kpoints = ref_kpoints.super_kpoints(ref_structure, self.poscar)
Beispiel #2
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)
Beispiel #3
0
def get_incar_tag(key, jobdir=None):
    """Opens INCAR in 'jobdir' and returns 'key' value."""
    if jobdir is None:
        jobdir = os.getcwd()
    tincar = incar.Incar(os.path.join(jobdir,"INCAR"))
    for k in tincar.tags:
        if key.lower() == k.lower():
            return tincar.tags[k]
    return None
Beispiel #4
0
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", end=' ')
    for s in extra_input_files:
        print("    ", s)
        shutil.copy(s, dirpath)

    print("  DONE\n")
    sys.stdout.flush()
Beispiel #5
0
def set_incar_tag(tag_dict,jobdir=None, name=None):
    """Opens INCAR in 'jobdir', sets 'key' value, and writes INCAR
        If 'val' is None, the tag is removed from the INCAR.
    """
    if name is None:
        name = "INCAR"
    if jobdir is None:
        jobdir = os.getcwd()
    incarfile = os.path.join(jobdir,name)
    tincar = incar.Incar(incarfile)

    for key, val in six.iteritems(tag_dict):
        for k in tincar.tags:
            if key.lower() == k.lower():
                if (val is None) or (str(val).strip() == ""):
                    del tincar.tags[k]
                else:
                    tincar.tags[k] = val
                break

        if val != None and str(val).strip() != "":
            tincar.tags[key] = val

    tincar.write(incarfile)
Beispiel #6
0
def write_vasp_input(dirpath,
                     incarfile,
                     ref_kpointsfile,
                     ref_structurefile,
                     structurefile,
                     speciesfile,
                     sort=True,
                     extra_input_files=[],
                     strict_kpoints=False):
    """ Write VASP input files in directory 'dirpath'

    Parameters
    ----------

    ref_structurefile: str
        Path to a CASM structure.json file or VASP POS/POSCAR file representing a reference structure used for scaling incar and k-point parameters.

    structurefile: str
        Path to a CASM structure.json file or VASP POS/POSCAR file representing the structure to be calculated.
    """
    print("Setting up VASP input files:", dirpath)

    # read reference structure and kpoints
    print("  Reading reference KPOINTS:", ref_kpointsfile)
    ref_kpoints = kp.Kpoints(ref_kpointsfile)
    if ref_structurefile != None:
        print("  Reading reference POSCAR:", ref_structurefile)
        ref_structure = poscar.Poscar(ref_structurefile)
    else:
        ref_structure = None

    # read species, prim structure.json/POS, and to-be-calculated
    # structure.json/POS, and use to construct incar and kpoints for
    # the to-be-calculated structure
    print("  Reading SPECIES:", speciesfile)
    species_settings = species.species_settings(speciesfile)
    if structurefile != None:
        print("  Reading structure:", structurefile)
        structure = poscar.Poscar(structurefile, species_settings)
    else:
        structure = None

    ## Reading DOF information present in the structure.json file
    ## Examples include: Cmagspin, NCmagspin, SOmagspin, etc
    ## Also contains information about atom types, and mol types
    print(" Reading DOF information from structure: ", structurefile)
    dof_info = attribute_info.AttributeInfo(structurefile)

    print("  Reading INCAR:", incarfile)
    incar = inc.Incar(incarfile, species_settings, structure, sort, dof_info)

    print("  Generating KPOINTS")
    if strict_kpoints:
        kpoints = ref_kpoints
    else:
        kpoints = ref_kpoints.super_kpoints(ref_structure, structure)

    # write main input files
    if structurefile != None:
        print("  Writing POSCAR:", os.path.join(dirpath, 'POSCAR'))
        structure.write(os.path.join(dirpath, 'POSCAR'), sort)
    print("  Writing INCAR:", os.path.join(dirpath, 'INCAR'))
    incar.write(os.path.join(dirpath, 'INCAR'))
    print("  Writing KPOINTS:", os.path.join(dirpath, 'KPOINTS'))
    kpoints.write(os.path.join(dirpath, 'KPOINTS'))
    if structurefile != None:
        print("  Writing POTCAR:", os.path.join(dirpath, 'POTCAR'))
        write_potcar(os.path.join(dirpath, 'POTCAR'), structure,
                     species_settings, sort)
    # copy extra input files
    if len(extra_input_files):
        print("  Copying extra input files", end=' ')
    for s in extra_input_files:
        print("    ", s)
        shutil.copy(s, dirpath)

    print("  DONE\n")
    sys.stdout.flush()