Exemplo n.º 1
0
def structure_to_gulp(iof,
                      struct,
                      runspec="single conp",
                      postcards=[],
                      potentials=None):
    """
    Writes a file on gulp input format.
    """
    iof = httk.IoAdapterFileWriter.use(iof)
    f = iof.file

    f.write(str(runspec) + "\n")
    f.write("cell\n")
    f.write("  " + str(struct.a) + " " + str(struct.b) + " " + str(struct.c) +
            " ")
    f.write(
        str(struct.alpha) + " " + str(struct.beta) + " " + str(struct.gamma) +
        "\n")
    f.write("fractional\n")
    for i in range(struct.N):
        species = periodictable.atomic_symbol(struct.p1occupancies[i])
        f.write(species + " ")
        f.write(" ".join([str(float(x)) for x in struct.p1coords[i]]) + "\n")
        #print("X",species+str(idx)+" "+" ".join([str(float(x)) for x in struct.coords[i]])+"\n")
    for card in postcards:
        f.write(card + "\n")
    if potentials is None:
        f.write(generate_fake_potentials(set(struct.p1assignments)))
    f.write("\n")
    iof.close()
Exemplo n.º 2
0
def generate_fake_potentials_try2(species):
    potentials = ""
    potentials += "epsilon\n"
    for s1 in species:
        ss1 = periodictable.atomic_symbol(s1)
        ns1 = periodictable.atomic_number(s1)
        #potentials += "%s core %.4f %.4f 0 0\n" % (ss1,sqrt(0.5*ns1),pow(0.75*ns1,3.0/2.0))
        #        potentials += "%s core %.4f %.4f 0 0\n" % (ss1,pow(ns1,0.9783276738),pow(ns1,1.124243243))
        potentials += "%s core %.4f %.4f 0 0\n" % (ss1, 0.1 * ns1, 0.1 * ns1)

    potentials += "lennard zero epsilon combine all\n"
    potentials += "0.0 12.0\n"

    return potentials
Exemplo n.º 3
0
def generate_fake_potentials(species):
    potentials = ""
    potentials += "atomab\n"
    for s1 in species:
        ss1 = periodictable.atomic_symbol(s1)
        ns1 = periodictable.atomic_number(s1)
        potentials += "%s core %.4f %.4f 0 0\n" % (ss1, sqrt(
            0.5 * ns1), pow(0.75 * ns1, 3.0 / 2.0))
    #potentials = "lennard combine 12 6\n"
    potentials += "lennard 12 6 combine all\n"
    potentials += "0.0 20.0\n"
    #for s1 in species:
    #    ss1 = periodictable.atomic_symbol(s1)
    #    for s2 in species:
    #        ss2 = periodictable.atomic_symbol(s2)
    #        potentials += "%s core %s core %.4f %.4f\n" % (ss1, ss2,0.0,10.0)

    return potentials
Exemplo n.º 4
0
 def symbol(self):
     #if self.extended:
     #    raise Exception("SiteAssignment: cannot convert extended site assignment into just a symbol.")
     return periodictable.atomic_symbol(self.atomic_number)
Exemplo n.º 5
0
def uc_reduced_coordgroups_process_with_isotropy(coordgroup,
                                                 cell,
                                                 get_wyckoff=False):
    #print("GURK",struct.formula,len(struct.uc_reduced_coords))

    inputstr = httk.iface.isotropy_if.reduced_coordgroups_to_input(
        coordgroup, cell)
    out, err, completed = isotropy("./", [], inputstr)
    if completed == 0:
        cif = httk.iface.isotropy_if.out_to_cif(
            IoAdapterString(string=out),
            [atomic_symbol(x) for x in range(1,
                                             len(coordgroup) + 1)])
        #print("CIF",cif)
        newstruct = cif_to_struct(IoAdapterString(string=cif),
                                  backends=['cif2cell_reduce'])
        checkstruct = cif_to_struct(IoAdapterString(string=cif),
                                    backends=['cif2cell'])
        only_rc_struct = cif_to_struct(
            IoAdapterString(string=cif),
            backends=['cif_reader_that_can_only_read_isotropy_cif'])
        # This is an illeelegant hack
        newstruct.rc_sites.wyckoff_symbols = only_rc_struct.rc_sites.wyckoff_symbols
        # Cell basis can only be constructed from the cif approximately
        cell_mismatch = sum(
            sum((checkstruct.rc_cell.basis -
                 only_rc_struct.rc_cell.basis))).to_float()
        #print("CELL MISMATCH:",sum(sum((newstruct.cell.maxnorm_basis - only_rc_struct.cell.maxnorm_basis))).to_float())
        only_rc_struct._rc_cell = newstruct.rc_cell
        # Make sure the hexhash is recomputed
        only_rc_struct.rc_sites._hexhash = None
        #print("CHECK THIS:", newstruct.rc_sites.hexhash, only_rc_struct.rc_sites.hexhash)
        #print("CHECK THIS:", newstruct.cell.to_tuple(), only_rc_struct.cell.to_tuple())
        if cell_mismatch > 1e-6 or newstruct.rc_sites.hexhash != only_rc_struct.rc_sites.hexhash:
            print("Cell mismatch:", cell_mismatch)
            print("Structure hashes:", newstruct.rc_sites.hexhash,
                  only_rc_struct.rc_sites.hexhash)
            #print("Structures:", newstruct.rc_sites.to_tuple(), only_rc_struct.rc_sites.to_tuple())
            raise Exception(
                "isotropy_ext.struct_process_with_isotropy: internal error, structures that absolutely should be the same are not, sorry."
            )

        #order = [x.as_integer-1 for x in newstruct.assignments]
        #print("ORDER:",order)

        if get_wyckoff:
            return newstruct.rc_reduced_coordgroups, newstruct.rc_sites.wyckoff_symbols, [
                [atomic_number(x) for x in y]
                for y in newstruct.assigments.symbols_list()
            ]
        else:
            return newstruct.rc_reduced_coordgroups
    else:
        print("ISOTROPY STDERR:")
        #print(inputstr)
        print("========")
        #print(out)
        #print("========")
        print(err)
        print("========")

        raise Exception("isotropy_ext: isotropy did not complete.")
Exemplo n.º 6
0
def prepare_single_run(dirpath,
                       struct,
                       poscarspath=None,
                       template='t:/vasp/single/static',
                       overwrite=False):
    if overwrite:
        mkdir_p(dirpath)
    else:
        os.mkdir(dirpath)
    structure_to_poscar(os.path.join(dirpath, "POSCAR"),
                        struct,
                        fix_negative_determinant=True)
    #write_generic_kpoints_file(os.path.join(dirpath,"KPOINTS"),comment=structure_to_comment(struct))
    kpoints = calculate_kpoints(struct)
    write_kpoints_file(os.path.join(dirpath, "KPOINTS"),
                       kpoints,
                       comment=structure_to_comment(struct))
    ioa = IoAdapterFileWriter.use(os.path.join(dirpath, "POTCAR"))
    f = ioa.file
    spieces_counts = []
    magmomlist = get_magnetizations(struct.symbols, 5, 1)
    magmom_per_ion = magmomlist[0]
    magmoms = []
    nelect = 0
    natoms = 0
    nmag = 0
    for i in range(len(struct.assignments)):
        assignment = struct.assignments[i]
        count = struct.uc_counts[i]
        symbol = periodictable.atomic_symbol(assignment.symbol)
        pp = get_pseudopotential(symbol, poscarspath)
        f.write(pp)
        spieces_counts.append(count)
        #magmoms.append(str(count)+"*"+str(get_magmom(symbol)))
        magmom = magmom_per_ion[i]
        magmoms.append(str(count) + "*" + str(magmom))

        def zval(results, match):
            results['zval'] = float(match.group(1))

        results = micro_pyawk(IoAdapterString(pp),
                              [["^ *POMASS.*; *ZVAL *= *([^ ]+)", None, zval]])
        if not 'zval' in results:
            raise Exception(
                "vasp_if.prepare_simple_static_run: Could not read ZVAL from potcar file"
            )
        nelect += results['zval'] * count
        natoms += count
        nmag += count * magmom

    ioa.close()
    nbands1 = int(0.6 * nelect + 1.0) + int(math.ceil(natoms / 2.0) + 0.1)
    nbands2 = int(0.6 * nelect + 1.0) + int(math.ceil(nmag / 2.0) + 0.1)
    nbands3 = int(0.6 * nelect + 1.0) + 20
    nbands_spin = max(1, nbands1, nbands2, nbands3)
    nbands_spin += nbands_spin % 2
    nbands1 = int(nelect / 2.0 + 2) + int(math.ceil(natoms / 2.0) + 0.1)
    nbands2 = int(math.ceil(nelect / 2.0) + 20 + 0.1)
    nbands_nospin = max(1, nbands1, nbands2)
    nbands_nospin += nbands_spin % 2

    data = {}
    data['VASP_SPIECES_COUNTS'] = " ".join(list(map(str, spieces_counts)))
    data['VASP_MAGMOM'] = " ".join(list(map(str, magmoms)))
    data['VASP_NBANDS_SPIN'] = str(nbands_spin)
    data['VASP_NBANDS_NOSPIN'] = str(nbands_nospin)

    if template.startswith('t:'):
        template = os.path.join(httk.httk_root, 'Execution', 'tasks-templates',
                                template[2:])

    apply_templates(template, dirpath, envglobals=data, mkdir=False)