Beispiel #1
0
def choose_structures( _howmany, _min = 2, _max = 9 ):
  import random
  import numpy as np
  from pylada import crystal, enumeration

  lattice, str_list = list_all_structures( _min, _max )

  for i in  xrange(_howmany):
    nsupercell = random.randint(0, len(str_list)-1)
    while len(str_list[nsupercell][3]) == 0: 
      nsupercell = random.randint(0, len(str_list)-1)
    nstr = 0
    if len(str_list[nsupercell][3]) > 1: 
      nstr = random.randint(0, len(str_list[nsupercell][3])-1)

    supercell, flavorbase, smith = str_list[nsupercell][:3]
    x = str_list[nsupercell][3].pop(nstr)

    # creates structure
    structure = crystal.sStructure()
    structure.cell = np.dot(lattice.cell, supercell.hermite)
    crystal.fill_structure(structure)
    structure.scale = lattice.scale
    enumeration.as_structure(structure, x, flavorbase)
    yield crystal.Structure(structure)
Beispiel #2
0
def create_superstructure(groundstate, input):
  """ Creates a superstructure from existing structure. """
  from os.path import dirname, join
  from operator import itemgetter
  from numpy import dot
  from IPython.ipapi import get as get_ipy
  from pylada.crystal import fill_structure, vasp_ordered

  # sanity checks,
  assert "structure" in groundstate.jobparams,\
         ValueError("Could not find structure in ground-state job-dictionary.")
  assert hasattr(groundstate.functional, "Extract"),\
         ValueError("Could not find extraction class in ground-state job-dictionary.")
  
  ip = get_ipy()
  assert "current_jobfolder_path" in ip.user_ns,\
         RuntimeError("Could not find path for current job-dictionary.")
  rootdir = dirname(ip.user_ns["current_jobfolder_path"])
  # gets original lattice from job-dictionary.
  orig_structure = groundstate.jobparams["structure"]
  
  # Extracts computed lattice from ground state calculation.
  extract = groundstate.functional.Extract( join(rootdir, groundstate.name[1:]) )
  assert extract.success, RuntimeError("Ground-state computation was not successful.")
  lattice = extract.structure.to_lattice()

  # creates superstructure.
  cell = dot(lattice.cell, input.supercell)
  result = fill_structure(cell, lattice)
  assert len(result.atoms) != len(lattice.sites), \
         ValueError("Superstructure as large as lattice. Disable this line if that's ok.")

  # adds magnetic moment if necessary.
  if hasattr(orig_structure, "magmom"):
    assert extract.magnetization.shape[0] == len(lattice.sites),\
           RuntimeError("Could not find magnetization in ground-state's OUTCAR.")
    mlat = lattice.deepcopy()
    for atom, m in zip(mlat.sites, extract.magnetization[:,-1]):
      if abs(m) < 0.1: atom.type = '0'
      elif m < 0e0: atom.type = str(int(m-1))
      else: atom.type = str(int(m+1))
    moments = fill_structure(cell, mlat)
    result.magmom = [ int(i.type) for i in moments.atoms ]

  return vasp_ordered(result, attributes=["magmom"]), lattice
Beispiel #3
0
from os.path import exists, join
from math import ceil, sqrt
from numpy import dot, array, matrix
from numpy.linalg import norm
from boost.mpi import world
from pylada.vff import Vff
from pylada.crystal import Structure, Lattice, fill_structure
from pylada.escan import read_input

input = read_input("input.py")

structure = Structure()
structure.set_cell = (4, 0, 0.5),\
                     (0, 1,   0),\
                     (0, 0, 0.5)
structure = fill_structure(structure.cell)
for i, atom in enumerate(structure.atoms):
  atom.type = "Si" if i < len(structure.atoms)/2 else "Ge"


result_str = Structure()
result_str.scale = 5.450000e+00
result_str.set_cell = (4.068890e+00, -4.235770e-18, 5.083297e-01),\
                     (-1.694308e-17, 1.016103e+00, 2.238072e-18),\
                     (-2.252168e-03, 8.711913e-18, 5.083297e-01)
result_str.weight = 1.000000e+00
result_str.name = ""
result_str.energy = 0.0938967086716
result_str.add_atom = (0.000000e+00, 0.000000e+00, 0.000000e+00), "Si", 0,  0
result_str.add_atom = (2.541649e-01, 2.473273e-01, 2.541649e-01), "Si", 1,  0
result_str.add_atom = (3.567265e+00, 5.062000e-01, -8.956567e-03), "Si", 0,  0
Beispiel #4
0
""" Point charge + r^12 + r^6 model. """
clj.ewald_cutoff = 80 * Ry

clj.charges["A"] = -1.0
clj.charges["B"] =  1.0

structure = Structure()
structure.set_cell = (1,0,0),\
                     (0,1,0),\
                     (0,0,1)
structure.scale = 50
structure.add_atom = (0,0,0), "A"
structure.add_atom = (a0.rescale(angstrom)/structure.scale,0,0), "B"

print clj.ewald(structure).energy, hartree.rescale(eV)


from pylada.crystal.A2BX4 import b5
from pylada.crystal import fill_structure
from numpy import array
clj.ewald_cutoff = 20 * Ry
lattice = b5()
lattice.sites[4].type='A'
structure = fill_structure(lattice.cell, lattice)
structure.scale = 8.0

clj.charges["A"] =  3.0
clj.charges["B"] =  2.0
clj.charges["X"] = -2.0
print clj.ewald(structure).energy, -498.586
Beispiel #5
0
from math import fabs as abs
from numpy import array
from pylada.crystal import fill_structure
from pylada.escan import read_input
from pylada.escan.emass import Functional

input = read_input("input.py", namespace = {"Escan": Functional})

G = array([0,0,0], dtype="float64")
X = array([0,0,1], dtype="float64")
structure = fill_structure(input.vff.lattice.cell, input.vff.lattice)
input.escan.nbstates = len(structure.atoms) * 4 + 4
input.escan.tolerance = 1e-12

orig = input.escan( structure, direction=(0,0,1), outdir="results/emass/100", \
                      do_relax_kpoint=False, type="e" )
assert abs(orig.mass[0] - 0.4381) < 0.01 # Gamma conduction emass 

result = input.escan( structure, direction=((0,0,1), (1,1,1)), outdir="results/hmass", \
                      do_relax_kpoint=False, type="h", bandgap=orig.extract_bg )
assert abs(result.mass[0][0] - 0.2769) < 0.01 # Gamma conduction heavy hmass (100 direction)
assert abs(result.mass[0][2] - 0.2059) < 0.01 # Gamma conduction light hmass (100 direction)
assert abs(result.mass[1][0] - 0.6885) < 0.01 # Gamma conduction heavy hmass (111 direction)
assert abs(result.mass[1][2] - 0.1460) < 0.01 # Gamma conduction light hmass (111 direction)
Beispiel #6
0
from numpy import dot
from pylada.crystal import fill_structure, FreezeAtom
from pylada.vasp import read_input
from pylada.vasp.emass import reciprocal
from pylada.mpi import world

input = read_input("input.py")

structure = fill_structure(dot(input.lattice.cell, [[-1,0,0],[1,0,1],[1,1,0]]), input.lattice)
for atom in structure.atoms: atom.freeze = FreezeAtom.x

input.relaxer.vasp.launch_as_library = True
input.relaxer.vasp.program = "vasp-4.6"
input.relaxer.vasp.vasp_library = "libvasp-4.6.so"
comm = world


result = reciprocal(input.relaxer, structure, outdir="results", comm=comm)
Beispiel #7
0
def read_database(filename, withperms=True):
  from numpy import array as np_array, dot as np_dot, zeros as np_zeros
  from pylada import crystal, enumeration

  lattice = crystal.Lattice()
  with open(filename, "r") as file:
    
    # reads lattice
    for line in file:
      data = line.split()
      if len(data) == 0: continue
      if data[0] == "cell:":
        lattice.cell = np_array(data[1:], dtype="float64").reshape(3,3)
      elif data[0] == "scale:":
        lattice.scale = float(line.split()[1])
      elif data[0] == "site:":
        data = line.split()
        data.pop(0)
        site = crystal.Site()
        for i in range(3): site.pos[i] = float(data.pop(0))
        while len(data): site.type.append( data.pop(0) )
        lattice.sites.append(site)
      elif data[0] == "endlattice": break

    lattice.set_as_crystal_lattice()
    transforms = enumeration.create_transforms(lattice)
    specialized = []
    nsites = len([0 for i in lattice.sites if len(i.type) > 1])

    hermite = None
    flavorbase = None
    transform = None
    structure = crystal.Structure()
    structure.scale = lattice.scale
    for line in file:
      data = line.split()
      if len(data) == 0: continue
      if data[0] == "n:": continue
      if data[0] == "hermite:":
        hermite = np_array(data[1:], dtype="float64").reshape(3,3)
        specialized = []
      elif data[0] == "transform:": 
        transform = np_array(data[1:], dtype="float64").reshape(3,3)
      elif data[0] == "smith:":
        smith = np_array( data[1:], dtype = "int64" )
        translations = enumeration.Translation(smith, nsites)
        cell = np_dot(lattice.cell, hermite)
        structure = crystal.fill_structure(cell)
        for transformation in transforms:
          if not transformation.invariant(cell): continue
          transformation.init(transform, smith)
          if not transformation.is_trivial:
            specialized.append( transformation )
      elif data[0] == "flavorbase:":
        card, nflavors = int(data[1]),  int(data[2])
        flavorbase = enumeration.create_flavorbase(card, nflavors)
        label_exchange=enumeration.LabelExchange(card, nflavors)
      elif len(data) > 0:
        assert flavorbase is not None
        assert hermite is not None
        for x in data:
          # adds label permutations that are not equivalent by affine transforms.
          x = int(x)
          others = set([x])
          if withperms:
            for labelperm in label_exchange:
              u = labelperm(x, flavorbase)
              if u in others: continue
  
              dont = False
              for transform in specialized:
                t = transform(u, flavorbase)
                if t in others:
                  dont = True
                  break
  
                for translation in translations:
                  v = translation(t, flavorbase)
                  if v in others:
                    dont = True
                    break
              if not dont: others.add(u)

          for u in others:
            enumeration.as_structure(structure, u, flavorbase)
            yield structure
Beispiel #8
0
from pylada.escan._escan import to_realspace
from pylada.escan._wfns import rtog_fourrier
from pylada.vff import Vff
from pylada.crystal import fill_structure, sort_layers, FreezeCell, nb_valence_states

# reads input file.
global_dict={"Vff": Vff, "Escan": Escan, "nb_valence_states": nb_valence_states, "soH": soH}
input = read_input("input.py", global_dict=global_dict)

# creating unrelaxed structure.
input.vff.lattice.set_as_crystal_lattice()
# cell = matrix([[0.5,-0.5,0],[0.5,0.5,0.5],[0,0,2.5]])
# structure = sort_layers(fill_structure(cell), array([0,0,2.5]))
# for i, atom in enumerate(structure.atoms):
#   atom.type = "Si" if i % 10 < 6 else "Ge"
structure = fill_structure(input.escan.vff.lattice.cell)
structure.atoms[0].type = "Si"
structure.scale = 5.55
structure.freeze = FreezeCell.a0 | FreezeCell.a1
input.escan.fft_mesh  = 14, 14, 14

out = input.escan( structure,\
                   outdir=join("results", "wfns"),\
                   comm=world )

with Changedir(out.directory) as directory:
  nbstates = out.escan.nbstates if out.escan.potential == soH and norm(out.escan.kpoint)\
             else out.escan.nbstates / 2
  out.raw_gwfns
  out.escan._write_incar(out.comm, out.structure)
  with redirect(fout="") as streams: