def main2():
    fname1 = "geometry/test_poscars/hackit.pos"
    A = pcread.poscar(fname1)
    fname2 = "geometry/test_poscars/hackit.pos"
    B = pcread.poscar(fname2)
    
    Astats = cell_stats(A.cell)
    Bstats = cell_stats(B.cell)

    m = np.array([[1,0,0],[0,1,1],[1,0,2]])
    A = supercell(A,np.dot(A.cell, m))
    Astats = cell_stats(A.cell)

    m = len(A)/len(B)  ## for now aSSUME m integer
    print "vol factor", m
    nmatch = 0

    print "target", Astats
    print A.cell

    allms = pickle.load(file("Ms_upto_2.pickle"))
#    allms = pickle.load(file("someMs.pickle"))

#    B = supercell(B, np.dot(B.cell, np.array([[m,0,0],[0,1,0],[0,0,1]])))
    Bcells = enum.supercells(B, [m])
    print "B.cell" 
    print B.cell
    print "all size m Bcells", Bcells
    for Bc in Bcells[m]:
        Bs = supercell(B, np.dot(B.cell, Bc))
        Bstats = cell_stats(Bs.cell)
        print "source", Bstats
        print Bs.cell

#    M = np.dot(npl.inv(B.cell), A.cell)
#    print "correct M (same as original m):"
#    print M

        print "testing like crazy:"

        for i in range(len(allms)):
            M = allms[i]
            newb = np.dot(Bs.cell, M)
            stats = cell_stats(newb)
            if (equal_stats(stats, Astats)):
                print "match", i, stats
                print "M="
                print M
                print "newb="
                print newb
                print "----"
                Btest = supercell(Bs, newb)
                fout = file("ucellX%d.tcl"% nmatch , "w")
                write_xyz_noopt(Btest, "B.X%d" %nmatch ,1, no_atoms=True)
                write_struct(fout, Btest, "B.X%d.xyz" %nmatch, 0, False)
                fout.close()
                nmatch += 1

                if nmatch > 4:
                    sys.exit()
Пример #2
0
def test_hlst():
    ctx = HLSTCtx()
    options, arg = get_options()
    src = pcread.poscar(options.A)
    dst = pcread.poscar(options.B)
    src = np.transpose(np.array([a.pos for a in src]))
    dst = np.transpose(np.array([a.pos for a in dst]))
    test_hlst_fit(ctx, src,dst,options)
Пример #3
0
def pmg_to_pyl_poscar(poscar : Poscar):
    from pylada.crystal import read, write
    import pylada.crystal
    with tempfile.NamedTemporaryFile() as f:
        poscar.write_file(f.name)
        pyl = read.poscar(f.name)
    return pyl
Пример #4
0
def main():
    options, arg = get_options()
    A = pcread.poscar(options.A)
    B = pcread.poscar(options.B)

    if (options.mode != "sym" and options.mode != "path"
            and options.mode != "opt"):
        print "mode must be one of: 'sym', 'path', 'opt'"
        sys.exit()

    if (options.mode == "sym"):
        explore_via_symmetry(A, B, options)
    elif (options.mode == "opt"):
        explore_via_optimization(A, B, options)
    else:
        # mode == path ...
        explore_via_pairing(A, B, options)
Пример #5
0
def test_segfault_issue_20():
    from os.path import join, dirname
    from pylada.crystal import Structure, primitive, read
    from pylada import error

    sc = read.poscar(join(dirname(__file__), 'issue20.poscar'))

    assert abs(primitive(sc, tolerance=1e-8).volume - sc.volume) < 1e-8
    with raises(error.RuntimeError):
        primitive(sc, tolerance=1e-5)
Пример #6
0
def test_incorrect_check_issue():
    """ potential cell not discarded despite being singular """
    from os.path import join, dirname
    from pylada.crystal import Structure, primitive, read
    from pylada import error

    sc = read.poscar(join(dirname(__file__), 'not_singular_cell.poscar'))

    # calling primitive used to throw an exception
    assert abs(primitive(sc, tolerance=1e-8).volume - 47.57971180103934) < 1e-8
Пример #7
0
def test_incorrect_check_issue():
    """ potential cell not discarded despite being singular """
    from os.path import join, dirname
    from pylada.crystal import Structure, primitive, read
    from pylada import error

    sc = read.poscar(join(dirname(__file__), 'not_singular_cell.poscar'))

    # calling primitive used to throw an exception
    assert abs(primitive(sc, tolerance=1e-8).volume - 47.57971180103934) < 1e-8
Пример #8
0
def test_segfault_issue_20():
    from os.path import join, dirname
    from pylada.crystal import Structure, primitive, read
    from pylada import error

    sc = read.poscar(join(dirname(__file__), 'issue20.poscar'))

    assert abs(primitive(sc, tolerance=1e-8).volume - sc.volume) < 1e-8
    with raises(error.RuntimeError):
        primitive(sc, tolerance=1e-5)
Пример #9
0
def pmg_to_pylada(pmg_structure):
    '''
    Converts a pylada structure to a pymatgen structure via a temporary file

    :param pylada_structure: Pylada structure to convert
    :return: Structure
    '''
    with tempfile.NamedTemporaryFile() as tmp:
        name = tmp.name
        pmg_structure.to('poscar', name)
        pylada_structure = read.poscar(name)
    return pylada_structure
Пример #10
0
def compute(outdir, common, **kwargs):
    from pylada.vasp import read_incar
    from pylada.crystal import read
    import os
    structure = read.poscar(kwargs["poscar"])
    vasp = read_incar(kwargs["incar"])

    for pot in kwargs["potcar"]:
        vasp.add_specie = pot.split("_")[0], os.path.join(
            os.environ["PAW"], pot)
    if "writechg" in kwargs.keys():
        vasp.lcharg = kwargs["writechg"]
    else:
        vasp.lcharg = True
    if "writewave" in kwargs.keys():
        vasp.lwave = kwargs["writewave"]
    else:
        vasp.lwave = True
    if "writeoptics" in kwargs.keys():
        vasp.loptics = kwargs["writeoptics"]
    else:
        vasp.loptics = False
    if "optcell" in kwargs.keys():
        if kwargs["optcell"] is not None:
            writeoptcell(outdir, kwargs["optcell"])
    if "chgcar" in kwargs.keys():
        copyorlinkfile(outdir, "CHGCAR", kwargs["chgcar"], "cp")
    if "wavecar" in kwargs.keys():
        copyorlinkfile(outdir, "WAVECAR", kwargs["wavecar"], "cp")
    if "dfile" in kwargs.keys():
        if not os.path.exists(os.path.join(outdir, "DFILE")):
            with open(os.path.join(outdir, "DFILE"), "w") as f:
                f.write(kwargs["dfile"])
    if "kpointscell" in kwargs.keys():
        import numpy as np
        kpoint = "Automatic generation\n0\nMonkhorst\n%d %d %d\n0 0 0"
        diag = np.diag(structure.cell)
        tmp = np.array(kwargs["kpointscell"]) // diag
        tmp[tmp == 0] = 1
        vasp.kpoints = kpoint % (tuple(tmp))
    else:
        if hasattr(vasp, "kspacing"):
            vasp.write_kpoints = nowritekpoints
        else:
            with open(kwargs["kpoints"], "r") as rfile:
                vasp.kpoints = rfile.read()
    try:
        result = vasp(structure, outdir=outdir, comm=common)
    except Exception as e:
        print("path:" + outdir)
        raise e
    return result
Пример #11
0
def strainstructure(orgposcar, strain, direct):
    import os
    import numpy as np
    from pylada.crystal import write, read
    outdir = gettmpdir()
    tmp_file_name = "POSCAR"
    tmp_path = os.path.join(outdir, tmp_file_name)
    structure = read.poscar(orgposcar)
    a = np.array([1.0, 1.0, 1.0])
    if direct == "a":
        a[0] = strain
    elif direct == "b":
        a[1] = strain
    elif direct == "c":
        a[2] = strain
    A = np.diag(a)
    structure.cell = structure.cell * A
    for atom in structure:
        atom.pos = atom.pos * a
    write.poscar(structure, tmp_path, vasp5=True)
    return tmp_path
def main3():
    from pylada.math import gruber
    fname1 = "geometry/test_poscars/hackit.pos"
    A0 = pcread.poscar(fname1)

    m = np.array([[1,0,0],[0,1,1],[0,0,2]])
    A = supercell(A0,np.dot(A0.cell, m))
    Ag = gruber(A.cell)

    m = np.array([[2,0,0],[0,1,0],[0,0,1]])
    B = supercell(A0,np.dot(A0.cell, m))
    Bg = gruber(B.cell)

    sa = cell_stats(Ag)
    print sa
    A2 = ang2vec(sa[3][0],sa[3][1],sa[3][2],sa[4][0],sa[4][1],sa[4][2])
    print Ag
    print A2
    sb = cell_stats(Bg)
    B2 = ang2vec(sb[3][0],sb[3][1],sb[3][2],sb[4][0],sb[4][1],sb[4][2])
    print Bg
    print B2
Пример #13
0
def test_istruc():
  from collections import namedtuple
  from pickle import loads, dumps
  from os import remove
  from os.path import join, exists
  from shutil import rmtree
  from tempfile import mkdtemp
  from pylada.vasp.files import POSCAR, CONTCAR
  from pylada.vasp import Vasp
  from pylada.crystal import Structure, read, specieset, write
  from pylada.error import ValueError

  structure = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name='has a name')\
                       .add_atom(0,0,0, "Si")\
                       .add_atom(0.25,0.25,0.25, "Si")

  Extract = namedtuple("Extract", ['directory', 'success', 'structure'])
  a = Vasp()
  o = a._input['istruc']
  d = {'IStruc': o.__class__}

  directory = mkdtemp()
  try: 
    assert a.istruc == 'auto'
    assert o.output_map(vasp=a, outdir=directory, structure=structure) is None
    assert eval(repr(o), d).value == 'auto'
    assert loads(dumps(o)).value == 'auto'
    assert exists(join(directory, POSCAR))
    remove(join(directory, POSCAR))

    # check reading from outcar but only on success.
    a.restart = Extract(directory, False, structure.copy())
    a.restart.structure[1].pos[0] += 0.02
    assert a.istruc == 'auto'
    assert o.output_map(vasp=a, outdir=directory, structure=structure) is None
    assert exists(join(directory, POSCAR))
    other = read.poscar(join(directory, POSCAR), types=specieset(structure))
    assert abs(other[1].pos[0] - 0.25) < 1e-8
    assert abs(other[1].pos[0] - 0.27) > 1e-8
    # check reading from outcar but only on success.
    a.restart = Extract(directory, True, structure.copy())
    a.restart.structure[1].pos[0] += 0.02
    assert a.istruc == 'auto'
    assert o.output_map(vasp=a, outdir=directory, structure=structure) is None
    assert exists(join(directory, POSCAR))
    other = read.poscar(join(directory, POSCAR), types=specieset(structure))
    assert abs(other[1].pos[0] - 0.25) > 1e-8
    assert abs(other[1].pos[0] - 0.27) < 1e-8

    # Now check CONTCAR
    write.poscar(structure, join(directory, CONTCAR))
    assert a.istruc == 'auto'
    assert o.output_map(vasp=a, outdir=directory, structure=structure) is None
    assert exists(join(directory, POSCAR))
    other = read.poscar(join(directory, POSCAR), types=specieset(structure))
    assert abs(other[1].pos[0] - 0.25) < 1e-8
    assert abs(other[1].pos[0] - 0.27) > 1e-8

    # Check some failure modes.
    write.poscar(structure, join(directory, CONTCAR))
    structure[0].type = 'Ge'
    a.restart = None
    try: o.output_map(vasp=a, outdir=directory, structure=structure)
    except ValueError: pass
    else: raise Exception()
    structure[0].type = 'Si'
    structure.add_atom(0.25,0,0, 'Si')
    try: o.output_map(vasp=a, outdir=directory, structure=structure)
    except ValueError: pass
    else: raise Exception()

  finally: rmtree(directory)
Пример #14
0
		def func(job):
			abspath = os.path.abspath(filename)
			if not os.path.exists(abspath):
				raise IOError("Can't found " + abspath)
			structure = read.poscar(abspath)
			job.params["structure"] = structure
Пример #15
0
def raw_anim(A, B, options):
    # just animate between A and B, straight up!
    ### this option is under development
    savedir = os.getcwd()
    os.chdir(options.trajdir)

    structure = pcread.poscar(options.A)
    structure = pcread.poscar(options.B)

    print "saving starting anim"
    Bpath = deepcopy(B)
    tag = "Bpath0"
    write_xyz(options, Bpath, tag, options.output_tiles)
    fout = file("%s.tcl" % tag, "w")
    write_struct(fout,
                 Bpath,
                 "%s.xyz" % tag,
                 0,
                 center=False,
                 bonds=True,
                 bond_len=options.bond_len)
    fout.close()

    # now write frames
    dt = 1.0 / (options.frames - 1)
    t = 0
    iter = 0
    eps = 1e-6
    curpos = []
    while t <= 1 + eps:
        Bpath = deepcopy(B)
        Bpath.cell = t * A.cell + (1.0 - t) * B.cell
        for i in range(len(apos)):
            pos = t * A[i].pos[i] + (1.0 - t) * B[i].pos[i]
            if (iter == 0):
                Bpath[i].pos = into_cell(
                    pos, Bpath.cell)  # then make sure it's _in_ the unit cell
                curpos.append(Bpath[i].pos)
            else:
                Bpath[i].pos = closest_to(pos, Bpath.cell, curpos[i])
                curpos[i] = Bpath[i].pos

        if (iter == 0):  ## testing/bug fixing
            from pylada.crystal import space_group, primitive
            from pylada.math import gruber
            Btest = primitive(Bpath)
            g = gruber(Btest.cell)
            print "src has cell:"
            print Btest.cell
            #            print g
            Btest = supercell(Btest, g)
            spacegroup = space_group(Btest)
            sg = spglib.get_spacegroup(Btest,
                                       symprec=1e-4,
                                       angle_tolerance=2.0)
            print "src has %d syms and sg %s" % (len(spacegroup), str(sg))
            Bstart = deepcopy(Bpath)

        sg = spglib.get_spacegroup(Bpath, symprec=1e-4, angle_tolerance=2.0)
        #        sg = spglib.get_spacegroup(Bpath, symprec=1e-1, angle_tolerance=10.0) ### debugging
        print t, sg, tag

        if (iter == options.frames - 1):  ## testing/bug fixing
            from pylada.crystal import space_group, primitive
            from pylada.math import gruber
            Btest = primitive(Bpath)
            g = gruber(Btest.cell)
            print "target has cell:"
            print Btest.cell
            #            print g
            Btest = supercell(Btest, g)
            spacegroup = space_group(Btest)
            sg = spglib.get_spacegroup(Btest,
                                       symprec=1e-4,
                                       angle_tolerance=2.0)
            print "target has %d syms and sg %s" % (len(spacegroup), str(sg))
            Bend = deepcopy(Bpath)

        tag = "traj.%d" % iter
        write_xyz(options, Bpath, tag, options.output_tiles)
        fout = file("%s.tcl" % tag, "w")
        write_struct(fout,
                     Bpath,
                     "%s.xyz" % tag,
                     0,
                     center=False,
                     bonds=True,
                     bond_len=options.bond_len)
        fout.close()

        # write poscar we can analyze later
        #        bigB = supercell(Bpath, np.dot(eye2,Bpath.cell))  # for writing a big poscar
        with open("%s.POSCAR" % tag, "w") as f:
            pcwrite.poscar(Bpath, f, vasp5=True)

        t += dt
        iter += 1

    os.chdir(savedir)
    if (options.verbose > 2):
        write_tcl(options, Bend, Bstart, pairs[1], "pairs")

    # some special work to verify we really arrived at B:


#    Borig = pcread.poscar(options.A)
#    M = np.dot(Borig.cell, npl.inv(Bpath.cell))
#    Bfinal = transform_cell(M,Bpath)
#    bigB = supercell(Bfinal, np.dot(eye2,Bfinal.cell))  ## this is a special "doubling" test
#    with open("final.POSCAR", "w") as f: pcwrite.poscar(bigB, f, vasp5=True)
#    with open("final.POSCAR", "w") as f: pcwrite.poscar(Bfinal, f, vasp5=True)
#    sg = spglib.get_spacegroup(Bfinal, symprec=1e-4, angle_tolerance=2.0)  ## this is "B in A coords"
#    print "spacegroup of final structure: ", sg
    sg = spglib.get_spacegroup(B, symprec=1e-4, angle_tolerance=2.0)
    print "spacegroup of initial structure (B, [Bflip in code]) ", sg
    sg = spglib.get_spacegroup(A, symprec=1e-4, angle_tolerance=2.0)
    print "spacegroup of target structure (A) ", sg
Пример #16
0
def anim_main(options):
    sgnum = []
    sgfull = []
    dat = []
    c2dat = []
    c2 = False
    for iter in range(options.frames):
        fname = "traj.%d.POSCAR" % iter
        fname = os.path.join(options.trajdir, fname)
        structure = pcread.poscar(fname)
        row = []
        if (c2):
            c2row = []
        for i in range(len(structure)):
            ## should just be doing this and be done:
            #            nb = neighbors(structure, 1, structure[i].pos, options.tol)
            ## but not quite working, so do this:
            nnb = get_nnb(structure, i, options.tol)
            if (c2):
                #vladan                cs = coordination_shells(structure, 2, structure[i].pos, options.tol)
                cs = get_2shells(structure, i, options.tol)

#            print "cs = ", cs
#            print "nb = ", nb
#            row.append(len(nb))
            row.append(nnb)
            #row.append(len(cs[0])) # size of of 1st shell
            if (c2):
                #vladan                c2row.append([len(cs[0]),len(cs[0])]) # size of of 2nd shell
                c2row.append([len(cs[0]), len(cs[1])])  # size of of 2nd shell
        sg = spglib.get_spacegroup(structure,
                                   symprec=1e-4,
                                   angle_tolerance=2.0)
        sgfull.append(sg)
        sg = sg.split("(")[1].split(")")[0]
        sgnum.append(int(sg))

        dat.append(row)
        if (c2):
            c2dat.append(c2row)

    tot_coord_lost = 0
    tot_coord_gained = 0
    natoms = len(structure)
    if options.verbose > 0:
        print "#coordination for %s to %s transition:" % (options.B, options.A)
        if (options.verbose > 1):
            s = "#frame spacegroup : "
            for i in range(len(structure)):
                s += "atom%d " % i
            print s
    for i in range(len(dat)):
        s = "%d   %s %d :  " % (i, sgfull[i], sgnum[i])
        row = dat[i]
        if (c2):
            c2row = c2dat[i]
        for j in range(len(row)):
            if (i > 0):
                tot_coord_lost += max(
                    0, last_row[j] - row[j]
                )  ## counting how many total bonds have broken, not how many restored
                tot_coord_gained += max(
                    0, row[j] - last_row[j]
                )  ## counting how many total bonds gained, not how many broken
            if (c2):
                s += "%d/%d,%d   " % (row[j], c2row[j][0], c2row[j][1])
            else:
                s += "%d   " % (row[j])
        if (options.verbose > 1):
            print s
        last_row = row
    speed = "FAST" if (tot_coord_lost == 0
                       or tot_coord_gained == 0) else "SLOW"
    if (options.verbose > 0):
        print "#Total of %.2f (%.2f) bonds per atom broken (resp.,made) in %s to %s transition." % (
            tot_coord_lost / float(natoms), tot_coord_gained / float(natoms),
            options.B, options.A)
    print "This transition is likely to be ", speed

    if (options.A != None and options.verbose > 1):
        structure = pcread.poscar(options.A)
        sg = spglib.get_spacegroup(structure,
                                   symprec=1e-5,
                                   angle_tolerance=-1.0)
        #        sg = sg.split("(")[1].split(")")[0]
        s = "#A   %s   " % (sg)
        for i in range(len(structure)):
            nnb = get_nnb(structure, i, options.tol)
            s += "%d   " % nnb
        print s


#        test_shift(structure)

    if (options.B != None and options.verbose > 1):
        structure = pcread.poscar(options.B)
        sg = spglib.get_spacegroup(structure,
                                   symprec=1e-5,
                                   angle_tolerance=-1.0)
        #        sg = sg.split("(")[1].split(")")[0]
        s = "#B   %s   " % (sg)
        for i in range(len(structure)):
            nnb = get_nnb(structure, i, options.tol)
            s += "%d   " % nnb
        print s

    return speed == "FAST"
         dirs.append(subdir)
 if "non-magnetic" not in dirs: continue
 #            print "%6s/%20s"%(icsdno,subdir), a.total_energy
 #    print icsdno, len(E)
 if len(E) > 1:
     minidx = np.argsort(E)[0]
     minE = min(E)
     minEdir = dirs[minidx]
     E.pop(minidx)
     dirs.pop(minidx)
     if minEdir == "non-magnetic":
         if np.mean(E) - minE < 1 and np.std(
                 E
         ) > 0.05:  # print the ones with energy difference smaller than 1 eV
             atoms = read.poscar('%s/%s/%s/CONTCAR' %
                                 (jobdir, icsdno, "%s/relax_cellshape/0" %
                                  (dirs[0])))
             if np.std(E) / len(atoms) > 0.05:
                 print "%s/%20s,%6.2f, %3d, %6.2f, %6.2f" % (
                     icsdno, minEdir, minE, len(E) + 1, np.mean(E),
                     np.std(E) / len(atoms))
     else:
         nonmagidx = [
             j for j in range(len(dirs)) if dirs[j] == "non-magnetic"
         ][0]
         nonmagE = E[nonmagidx]
         E.pop(nonmagidx)
         if np.std(E) > 0.05:
             atoms = read.poscar('%s/%s/%s/CONTCAR' %
                                 (jobdir, icsdno, "%s/relax_cellshape/0" %
                                  (dirs[0])))
Пример #18
0
def magmom(poscarsource):
    from pylada.crystal import read
    structure = read.poscar(poscarsource)
    magmom = "%d*0.6" % (len(structure) * 3)
    return magmom
Пример #19
0
def test_istruc():
    from collections import namedtuple
    from pickle import loads, dumps
    from os import remove
    from os.path import join, exists
    from shutil import rmtree
    from tempfile import mkdtemp
    from pylada.vasp.files import POSCAR, CONTCAR
    from pylada.vasp import Vasp
    from pylada.crystal import Structure, read, specieset, write
    from pylada.error import ValueError

    structure = Structure([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name='has a name')\
        .add_atom(0, 0, 0, "Si")\
        .add_atom(0.25, 0.25, 0.25, "Si")

    Extract = namedtuple("Extract", ['directory', 'success', 'structure'])
    a = Vasp()
    o = a._input['istruc']
    d = {'IStruc': o.__class__}

    directory = mkdtemp()
    try:
        assert a.istruc == 'auto'
        assert o.output_map(vasp=a, outdir=directory,
                            structure=structure) is None
        assert eval(repr(o), d).value == 'auto'
        assert loads(dumps(o)).value == 'auto'
        assert exists(join(directory, POSCAR))
        remove(join(directory, POSCAR))

        # check reading from outcar but only on success.
        a.restart = Extract(directory, False, structure.copy())
        a.restart.structure[1].pos[0] += 0.02
        assert a.istruc == 'auto'
        assert o.output_map(vasp=a, outdir=directory,
                            structure=structure) is None
        assert exists(join(directory, POSCAR))
        other = read.poscar(join(directory, POSCAR),
                            types=specieset(structure))
        assert abs(other[1].pos[0] - 0.25) < 1e-8
        assert abs(other[1].pos[0] - 0.27) > 1e-8
        # check reading from outcar but only on success.
        a.restart = Extract(directory, True, structure.copy())
        a.restart.structure[1].pos[0] += 0.02
        assert a.istruc == 'auto'
        assert o.output_map(vasp=a, outdir=directory,
                            structure=structure) is None
        assert exists(join(directory, POSCAR))
        other = read.poscar(join(directory, POSCAR),
                            types=specieset(structure))
        assert abs(other[1].pos[0] - 0.25) > 1e-8
        assert abs(other[1].pos[0] - 0.27) < 1e-8

        # Now check CONTCAR
        write.poscar(structure, join(directory, CONTCAR))
        assert a.istruc == 'auto'
        assert o.output_map(vasp=a, outdir=directory,
                            structure=structure) is None
        assert exists(join(directory, POSCAR))
        other = read.poscar(join(directory, POSCAR),
                            types=specieset(structure))
        assert abs(other[1].pos[0] - 0.25) < 1e-8
        assert abs(other[1].pos[0] - 0.27) > 1e-8

        # Check some failure modes.
        write.poscar(structure, join(directory, CONTCAR))
        structure[0].type = 'Ge'
        a.restart = None
        try:
            o.output_map(vasp=a, outdir=directory, structure=structure)
        except ValueError:
            pass
        else:
            raise Exception()
        structure[0].type = 'Si'
        structure.add_atom(0.25, 0, 0, 'Si')
        try:
            o.output_map(vasp=a, outdir=directory, structure=structure)
        except ValueError:
            pass
        else:
            raise Exception()

    finally:
        rmtree(directory)
Пример #20
0
        "Quartz_a", "Quartz_b", "Tridymite_a", "Tridymite_b", "Cristobalite_a",
        "Cristobalite_b", "Moganite", "Stishovite"
    ]

    procs = []
    a2 = []
    fnames = []
    for i in range(len(poscars) - 1):
        for j in range(len(poscars)):
            options.A = os.path.join(dir, "%s%s%s" % (pre, poscars[i], post))
            options.B = os.path.join(dir, "%s%s%s" % (pre, poscars[j], post))
            options.trajdir = os.path.join(
                tdir, "%s-to-%s" % (poscars[i], poscars[j]))

            if (direct):
                A = pcread.poscar(options.A)
                B = pcread.poscar(options.B)

                test_enum(A, B, options)
                anim_main(options)

            else:
                args = [
                    "python", "pmpaths.py", "-t", "1", "-b", "2.0", "-z",
                    options.trajdir, "-n", "231", "-A", options.A, "-B",
                    options.B
                ]
                if (run_pmpaths):
                    stdout = file("stdout.%s-to-%s" % (poscars[i], poscars[j]),
                                  "w")
                    print "starting pmpaths with", args
Пример #21
0
import pylada.crystal.read as pcread
import os
import re

tol = 1e-15
failed = False

with open("ExampleList") as exlist:
    for transition in exlist:
        transition = transition.strip()
        print "Checking %s, A to B" % transition
        test = os.listdir("./examples/%s/A2B_test" % transition)
        loopfail = False
        for i in range(len(test)):
            if re.match('.*\.POSCAR$', test[i]):
                A = pcread.poscar("./examples/%s/A2B_test/%s" %
                                  (transition, test[i]))
                B = pcread.poscar("./examples/%s/A2B/%s" %
                                  (transition, test[i]))
                cond_A = [(abs(A.cell - B.cell) < tol).all()]
                for j, a in enumerate(A):
                    cond_A.append(all(abs(a.pos - B[j].pos) < tol))
                    cond_A.append(a.type == B[j].type)
                cond_A = all(cond_A)
                if not cond_A:
                    failed = True
                    loopfail = True
                    print "Test failed for file %s" % (test[i])
        if not loopfail:
            print "Success"
        print "Checking %s, B to A" % transition
        test = os.listdir("./examples/%s/B2A_test" % transition)
Пример #22
0
vasp.lpead      = False
vasp.algo = "Normal"
vasp.relaxation = "ionic"

relax = Relax(copy=vasp)

relax.nsw=75
relax.minrelsteps= 4
relax.maxiter = 10
relax.keep_steps = True
relax.first_trial = { "kpoints": "\n0\nAuto\n10", "encut": 0.9 }

############### setting up the structures

# input bulk primitive cell
In2O3prim = read.poscar('POSCAR_In2O3')

# create bulk supercell
In2O3_sc = supercell(In2O3prim,np.diag([In2O3prim.cell[0][0]*2., In2O3prim.cell[1][1]*2., In2O3prim.cell[2][2]*2.]))

# create list of job folders
calcs = ['epsilon', 'SC', 'Ini', 'VIn', 'OIn']

structures = {}

for calc in calcs:
    if calc=='epsilon':
        structure=deepcopy(In2O3prim)
        structures[calc]=structure

    else:
    E = []
    dirs = []
    for subdir in subdirs:
        a = vasp.Extract('%s/%s/%s'%(jobdir,icsdno, subdir))
        if a.success:
            E.append(a.total_energy.magnitude)
            dirs.append(subdir)
    if "non-magnetic" not in dirs: continue
#            print "%6s/%20s"%(icsdno,subdir), a.total_energy
#    print icsdno, len(E)
    if len(E) > 1:
        minidx = np.argsort(E)[0]
        minE = min(E)
        minEdir = dirs[minidx]
        E.pop(minidx)
        dirs.pop(minidx)
        if minEdir == "non-magnetic":
            if np.mean(E) - minE < 1 and np.std(E) > 0.05: # print the ones with energy difference smaller than 1 eV
                atoms = read.poscar('%s/%s/%s/CONTCAR'%(jobdir, icsdno, "%s/relax_cellshape/0"%(dirs[0])))
                if np.std(E) / len(atoms) > 0.05:
                    print "%s/%20s,%6.2f, %3d, %6.2f, %6.2f"%(icsdno, minEdir, minE, len(E)+1, np.mean(E), np.std(E)/len(atoms))
        else:
            nonmagidx = [j for j in range(len(dirs)) if dirs[j] == "non-magnetic"][0]
            nonmagE = E[nonmagidx]
            E.pop(nonmagidx)
            if np.std(E) > 0.05:
                atoms = read.poscar('%s/%s/%s/CONTCAR'%(jobdir, icsdno, "%s/relax_cellshape/0"%(dirs[0])))
                if np.std(E) / len(atoms) > 0.05:                
                    print "%s/%20s,%6.2f, %3d, non-magnetic, %6.2f, %6.2f, %6.2f"%(icsdno, minEdir, minE, len(E)+2, nonmagE, np.mean(E), np.std(E)/len(atoms))