コード例 #1
0
ファイル: check.py プロジェクト: georgeyumnam/pylada
def enum( _n, _lattice ):
  import numpy as np
  from pylada import enumeration
  from math import pow

  supercells = enumeration.find_all_cells(_lattice, _n)
  smiths = enumeration.create_smith_groups(_lattice, supercells)
  nflavors = enumeration.count_flavors(_lattice)
  nsites = len(_lattice.sites)
  transforms = enumeration.create_transforms(_lattice)
  for smith in smiths:
    card = int(smith.smith[0]*smith.smith[1]*smith.smith[2]*nsites)
    label_exchange=enumeration.LabelExchange( card, nflavors )
    flavorbase = enumeration.create_flavorbase(card, nflavors)
    translations = enumeration.Translation(smith.smith, nsites)
    database = enumeration.Database(card, nflavors)
    maxterm = 0
    for x in xrange(1, int(pow(nflavors, card))-1):
      if not database[x]: continue
      maxterm = x
      for labelperm in label_exchange:
        t = labelperm(x, flavorbase)
        if t > x: database[t] = False
      for translation in translations:
        t = translation(x, flavorbase)
        if t > x: database[t] = False
        elif t == x: 
          database[t] = False
          continue
        for labelperm in label_exchange:
          u = labelperm(t, flavorbase)
          if u > x: database[u] = False

    # checks supercell dependent transforms.
    for nsupercell, supercell in enumerate(smith.supercells):
      mine = []
      # creates list of transformation which leave the supercell invariant.
      cell = np.dot(_lattice.cell,  supercell.hermite)
      specialized = []
      for transform in transforms:
        if not transform.invariant(cell): continue
        transform.init(supercell.transform, smith.smith)
        if not transform.is_trivial:
          specialized.append( transform )

      specialized_database = enumeration.Database(database)
      for x in xrange(1, maxterm+1):
        if not database[x]: continue
        maxterm = x
        
        for transform in specialized:
          t = transform(x, flavorbase)
          if t == x: continue
          specialized_database[t] = False

          for labelperm in label_exchange:
            u = labelperm(t, flavorbase)
            if u == x: continue
            specialized_database[u] = False
            
          for translation in translations:
            u = translation(t, flavorbase)
            if u == x: continue
            specialized_database[u] = False
            for labelperm in label_exchange:
              v = labelperm(u, flavorbase)
              if v == x: continue
              specialized_database[v] = False
        if specialized_database[x]: yield x, smith, supercell, flavorbase
コード例 #2
0
ファイル: database.py プロジェクト: mdavezac/LaDa
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