Пример #1
0
  def main( self ):
    (opts, args) = self.parse()

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    inp = IO( opts.input,'POSCAR', "r", sysopts )
    inp.read()
    geom = inp.geom()

    if opts.select != None:
      aid = int(opts.select)
      cmd = "select"
    if opts.delete != None:
      aid = int(opts.delete)
      cmd = "delete"
    # end if

    atom = geom.get(aid)
    atom.info()

    if geom.pt == PT.Cart:
      dp = geom.position( atom, PT.Direct )
      cp = atom.position
    else:
      dp = atom.position
      cp = geom.position( atom, PT.Cart )
    # end if

    print " Frac : %21.16f%21.16f%21.16f" % (dp[0],dp[1],dp[2])
    print " Cart : %21.16f%21.16f%21.16f" % (cp[0],cp[1],cp[2])
Пример #2
0
  def main( self ):
    (opts, args) = self.parse()
    opts_sys = { "verbose" : self.verbose, "debug" : self.debug }

    try:
      inp  = IO( opts.input,'POSCAR', "r", opts_sys )
      inp.read()
    except:
      if self.debug:
        raise
      else:
        print "Input not found:", opts.input
        sys.exit(1)

    geom = inp.geom()

    try:
      band=[]
      with open(opts.band) as f:
        for line in f:
          line = line.split()
          if len(line) == 0:
            continue
          if line[0] == 'tot' or line[0] == 'band':
            continue
          # print len(line)
          band.append([string.atoi(line[0]), string.atof(line[10]) ])
    except:
      raise
    else:
      print band
      # sys.exit(1)

    fileio = 'POSCAR'
    if opts.cart:
      opts_pt = { 'pt' : PT.Cart }
    else:
      opts_pt = { 'pt' : PT.Direct }

    if opts.xyz:
      opts.output += '.xyz'
      fileio = 'xyz'
      opts_pt = { 'pt' : PT.Cart }
    else:
      opts.output += '.POSCAR'
    # end if
    try:
      out = IO( opts.output, fileio, "w+", opts_sys )
      out.geom( geom )
      if len(band) != 0:
        out_geom = out.geom()
        out_geom.band(band)
      out.write( opts )
    except:
      if self.debug:
        raise
      else:
        print "Output failed:", opts.output
        sys.exit(1)
Пример #3
0
  def main( self ):
    (options, args) = self.par()

    try:
      atomlist  = self.cfgarri( 'atomlist' )
    except:
      print ' Error: no atomlist'
      return 0
    # end try

    try:
      reference = self.cfg( 'reference' )
    except:
      reference = None
    # end try

    try:
      origo_vec = self.cfgarrf( 'origo_vec' )
    except:
      origo_vec = numpy.zeros(3)
    # end try

    try:
      vacancy = self.cfgarri( 'vacancy' )
    except:
      vacancy = None
    # end try

    try:
      lat_vec = self.cfgarrf( 'lat_vec' )
    except:
      lat_vec = None
    # end try


    sysopts = { "verbose" : self.verbose, "debug" : self.debug }
    input_file = options.input_name
    input_upot = IO( input_file, 'UPOT', "r", sysopts )
    input_upot.read()

    ref = None
    if reference != None :
      reference_upot = FIO( reference, 'UPOT', "r", sysopts )
      reference_upot.read()
      ref = reference_upot.handler
    # end if

    avg_cl_shift = input_upot.command( 'average', { 'atomlist'  : atomlist, 
                                                    'lat_vec'   : lat_vec,
                                                    'origo_vec' : origo_vec,
                                                    'vacancy'   : vacancy,
                                                    'reference' : ref } )
    # end if
    print
    print ' Average Potential:', avg_cl_shift
    print
Пример #4
0
  def main( self ):
    (options, args) = self.par()
    input_name  = options.input_name
    output_name = options.output_name
    pt = PT.Cart
    if options.direct:
      pt = PT.Direct
    # end if
    output_name += "."+PTD[pt]

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    input_file  = IO( input_name,'POSCAR', "r", sysopts )
    input_file.read()
    geom = input_file.geom()

    fileio = 'POSCAR'
    opts = { 'pt' : pt }
    if options.xyz:
      output_name += '.xyz'
      fileio = 'xyz'
      opts = { 'pt' : PT.Cart }
    else:
      output_name += '.POSCAR'
    # end if
    output_file = IO( output_name,fileio, "w+", sysopts )
    output_file.geom( geom )
    output_file.write( opts )
Пример #5
0
  def main( self ):
    (options, args) = self.par()

    try:
      msc = self.cfgarri( 'msc' )
      msc = msc.reshape([3,3])
    except:
      print ' Error: no supercell matrix'
      return 0
    # end try

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }
    input_file = options.input_name
    input_pos = IO( input_file, 'POSCAR', "r", sysopts )
    input_pos.read()

    super_geom = input_pos.geom().supercell( msc )
Пример #6
0
  def main( self ):
    (options, args) = self.par()
    input_name  = options.input_name
    select = int(options.select)

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    input_file  = IO( input_name,'POSCAR', "r", sysopts )
    input_file.read()
    geom = input_file.geom()
    atom = geom.get(select)
    atom.info()

    if geom.pt == PT.Cart:
      dp = geom.position( atom, PT.Direct )
      cp = atom.position
    else:
      dp = atom.position
      cp = geom.position( atom, PT.Cart )
    # end if

    print " Frac : %21.16f%21.16f%21.16f" % (dp[0],dp[1],dp[2])
    print " Cart : %21.16f%21.16f%21.16f" % (cp[0],cp[1],cp[2])
Пример #7
0
  def main( self ):
    (options, args) = self.par()
    input_name  = options.input_name
    trans_name  = options.trans_name
    output_name = options.output_name

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    # read input geometry
    input_file = IO( input_name, 'POSCAR', 'r', sysopts )
    input_file.read()

    # transform
    trans_file = LX( trans_name, 'TF', sysopts )
    trans_file.geom( input_file.geom() )
    geom = trans_file.read()

    # output
    opts = { 'pt' : PT.Cart }
    output_file = IO( output_name, 'POSCAR', "w+", sysopts )
    output_file.geom( geom )
    output_file.write( opts )
Пример #8
0
  def average_upot( self, argv = None ):
    atomlist = argv['atomlist']
    ref      = argv['reference']
    vacancy  = argv['vacancy']
    spec = {}
    avg_cl_shift = 0.000

    # lattice vectors
    try:
      lat_vec = argv['lat_vec']
      self.geom.lat_vec = numpy.reshape( lat_vec, ( 3, 3 ) )
      if ref != None:
        ref.geom.lat_vec = numpy.reshape( lat_vec, ( 3, 3 ) )
      # end if
      msg = PTD[PT.Cart]
      # cart origo?
      try:
        origo_vec = argv['origo_vec']
      except:
        origo_vec = None
      # end try
    # end if
    except:
      lat_vec = None
      msg = PTD[PT.Direct]
    # end try
    if self.verbose:
      print " Coords:",msg
    # end if

    if lat_vec != None:
      avg_xyz = Geometry()
      avg_xyz.lat_vec = self.geom.lat_vec
      avg_xyz.pt = PT.Cart
    # end if

    if self.verbose:
      msg = "\n  %5s %4s %12s %12s %12s %12s" % ("No","Sym","cl_shift","x","y","z")
      if origo_vec != None:
        msg += " %12s" % ("dr")
        if ref != None:
          msg += " %12s" % ("ref dr")
      print msg
    # end if

    # cross check
    if ref != None:
      lookup = l_vacancy( range( 0, ref.geom.ac ), vacancy )
      ref_avg_cl_shift = 0.000
    # end if

    for ai in atomlist:
      atom = self.geom.get( ai )
      s    = atom.symbol
      no   = atom.no
      cls  = atom.cl_shift
      pos  = atom.position
      avg_cl_shift += cls

      # cross check
      if ref != None:
        ref_atom = ref.geom.get( lookup[ai] )
        ref_s    = ref_atom.symbol
        ref_pos  = ref_atom.position
        ref_cls  = ref_atom.cl_shift
        ref_avg_cl_shift += ref_cls
      # end if

      # cart position
      if lat_vec != None:
        # change to cart
        pos = self.geom.position( atom, PT.Cart )
        if ref != None:
          ref_pos = ref.geom.position( ref_atom, PT.Cart )
        avg_xyz.add( AtomPos( s, no, cls, pos ) )
      # end if

      if self.verbose:
        msg  = "  %5d %4s" % (atom.no, s)
        msg += " %12.6f" % cls
        msg += " %12.6f %12.6f %12.6f" % (pos[0], pos[1], pos[2])
        if origo_vec != None and lat_vec != None:
          msg += " %12.6f" % v_dr( origo_vec, pos )
        # end if
        print msg

        if ref != None:
          msg  = "R %5d %4s" % (ref_atom.no, ref_s)
          msg += " %12.6f" % ref_cls
          msg += " %12.6f %12.6f %12.6f" % (ref_pos[0], ref_pos[1], ref_pos[2])
          if origo_vec != None and lat_vec != None:
            msg += " %12.6f" % v_dr( origo_vec, ref_pos )
            msg += " %12.6f" % v_dr( ref_pos, pos )
          # end if
          print msg
        # end if
      # end if

      try:
        spec[s] += 1
      except:
        spec[s] = 1
      # end try
    # end for ai

    if self.verbose:
      print "\n Atoms: ", len( atomlist )
      print " Species: ", spec
      print "\n Orig. Average:", avg_cl_shift, "/", len( atomlist ), \
                        "=", avg_cl_shift / len( atomlist )
      if ref != None:
        print "  Ref. Average:", ref_avg_cl_shift, "/", len( atomlist ), \
                               "=", ref_avg_cl_shift / len( atomlist )
        print "\n Shift:", avg_cl_shift - ref_avg_cl_shift
      # end if

    # end if

    # end if
    if lat_vec != None:
      avg_output = IO( 'atomlist.xyz', 'xyz', 'w+' )
      avg_output.geom( avg_xyz )
      avg_output.write()
    # end if

    avg_cl_shift /= len( atomlist )
    return avg_cl_shift
Пример #9
0
  def main( self ):
    (opts, args) = self.parse()

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    ### begin reference
    try:
      print opts.reference,":"
      ref = IO( opts.reference, 'UPOT', "r", sysopts )
      ref.read()
    except:
      if self.debug:
        raise
      else:
        print "Reference failed:", opts.reference
        sys.exit(1)
    # end try

    # set geoms
    gref = ref.geom()

    # check furthest in reference
    if not opts.max == None:
      (origo,max) = opts.max.split(":")
      origo = int(origo)
      max = float(max)
      gref.furthest( origo, max )
      return
    # end if
    ### end reference

    ### begin input
    try:
      inp = IO( opts.input, 'UPOT', "r", sysopts )
      print opts.input,":"
      inp.read()
    except:
      if self.debug:
        raise
      else:
        print "Input failed:", opts.input
        sys.exit(1)
    # end try
    gref.geom = inp.geom()
    ### end input

    if not opts.compare == None:
      complist = {}
      pairs = opts.compare.split(",")
      for p in pairs:
        (k,v) = p.split(":")
        complist[k] = v
      # end for
      print
      ref.compare( complist )
      return
    # end if

    # warning: geoms should have the same lattice
    # generate match table
    if not opts.match == None:
      if not opts.cache == None:
        match = open( opts.cache, 'wb' )
      # end if
      gref.match( opts.match )
      # write out match cache
      if not opts.cache == None:
        pickle.dump(gref.geom_match,match,-1)
        return
      # end if
    # end if

    if not opts.average == None:
      if not opts.cache == None:
        match = open( opts.cache, 'rb' )
        gref.geom_match = pickle.load( match )
        match.close()
      else:
        raise Exception( "Cache error" )
      # end if

      print
      ref.average( opts.average.split(":") )
Пример #10
0
  def main( self ):
    (options, args) = self.par()
    input_name  = options.input_name
    output_name = options.output_name
    ref_name    = options.ref_name
    ul = options.ul
    ll = options.ll

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    # read input geometry
    input_file = IO( input_name, 'POSCAR', 'r', sysopts )
    input_file.read()

    ref_file = IO( ref_name, 'POSCAR', 'r', sysopts )
    ref_file.read()

    # geom check
    igeom = input_file.geom()
    rgeom = ref_file.geom()

    print "Reference: " + ref_name + "  New: " + input_name
    dgeom = rgeom.diff( igeom, ll, ul, options.newno )

    # output
    opts = { 'pt' : PT.Cart }
    output_file = IO( output_name, 'diff', "w+", sysopts )
    output_file.geom( dgeom )
    output_file.write( opts )
Пример #11
0
  def main( self ):
    (opts, args) = self.parse()

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    ### begin reference
    try:
      print opts.reference,":"
      ref = IO( opts.reference, 'ASEPOT', "r", sysopts )
      ref.read()
    except:
      if self.debug:
        raise
      else:
        print "Reference failed:", opts.reference
        sys.exit(1)
    # end try

    # set geoms
    gref = ref.geom()
    if opts.poscar:
      out = IO( 'vsasepot.ref.POSCAR', 'POSCAR', "w+", sysopts )
      out.geom( gref )
      out.write()
    # end if

    # G2012-04-27
    if not opts.origo == None:
      gref.shift_origo(opts.origo)
    # end if

    # check furthest in reference
    if not opts.rho == None:
      rho = float( opts.rho )
      crop = gref.cart_select( rho )
      if crop.ac == 0:
        print "EMPTY SELECTION, SET SMALLER RHO"
        sys.exit(1)

      out = 'ref.crop.POSCAR'
      out = IO( out, 'POSCAR', "w+", sysopts )
      out.geom( crop )
      out.write()

      # for atom in crop.atoms:
      #   atom.info()
      # # end for
    # end if
    ### end reference


    ### begin input
    try:
      inp = IO( opts.input, 'ASEPOT', "r", sysopts )
      print opts.input,":"
      inp.read()
    except:
      if self.debug:
        raise
      else:
        print "Input failed:", opts.input
        sys.exit(1)
    # end try
    igeom = inp.geom()
    igeom.geom = crop
    ### end input

    if not opts.vacancy == None:
      vaclist = opts.vacancy.split(",")
      for i in range(0,len(vaclist)):
        vaclist[i] = int(vaclist[i])
      # end for
      crop = inp.average( vaclist )
      out  = 'inp.crop.POSCAR'
      out  = IO( out, 'POSCAR', "w+", sysopts )
      out.geom( crop )
      out.write()
      return
    # end if

    if not opts.compare == None:
      complist = {}
      pairs = opts.compare.split(",")
      for p in pairs:
        (k,v) = p.split(":")
        complist[k] = v
      # end for
      print
      ref.compare( complist )
      return
    # end if

    # warning: geoms should have the same lattice
    # generate match table
    if not opts.match == None:
      if not opts.cache == None:
        match = open( opts.cache, 'wb' )
      # end if
      gref.match( opts.match )
      # write out match cache
      if not opts.cache == None:
        pickle.dump(gref.geom_match,match,-1)
        return
      # end if
    # end if

    if not opts.average == None:
      if not opts.cache == None:
        match = open( opts.cache, 'rb' )
        gref.geom_match = pickle.load( match )
        match.close()
      else:
        raise Exception( "Cache error" )
      # end if

      print
      ref.average( opts.average.split(":") )
Пример #12
0
  def main( self ):
    (options, args) = self.par()
    input_name  = options.input_name
    output_name = options.output_name
    diff_name   = options.diff_name

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }

    # read input geometry
    input_file = IO( input_name, 'POSCAR', 'r', sysopts )
    input_file.read()

    diff_file = IO( diff_name, 'diff', 'r', sysopts )
    diff_file.read()

    geom  = input_file.geom()
    dgeom = diff_file.geom()
    pgeom = geom.patch( dgeom )

    # output
    opts = { 'pt' : PT.Cart }
    output_file = IO( output_name, 'POSCAR', "w+", sysopts )
    output_file.geom( pgeom )
    output_file.write( opts )
Пример #13
0
  def main( self ):
    (opts, args) = self.parse()

    opts_sys = { "verbose" : self.verbose, "debug" : self.debug }

    # read input
    # IO  filename  type  mode  options
    try:
      inp = IO( opts.input, 'POSCAR', 'r', opts_sys )
      inp.read()
    except:
      if self.debug:
        raise
      else:
        print "Input not found:", opts.input
        sys.exit(1)
    # end try

    # do transformation
    # LX  transfile type options
    try:
      trs = LX( opts.trans, 'TF', opts_sys )
      trs.geom( inp.geom() )
      # build & process
      geom = trs.read()
    except:
      if self.debug:
        raise
      else:
        print "Transformation error:", opts.trans
        sys.exit(1)
    # end try

    # write output
    # IO  filename  type  mode  options
    try:
      out = IO( opts.output, 'POSCAR', "w+", opts_sys )
      out.geom( geom )
      if opts.cart:
        out.write( { 'pt' : PT.Cart } )
      else:
        out.write( { 'pt' : PT.Direct } )
    except:
      if self.debug:
        raise
      else:
        print "Output failed:", opts.output
        sys.exit(1)
Пример #14
0
  def main( self ):
    (opts, args) = self.parse()

    opts_sys = { "verbose" : self.verbose, "debug" : self.debug }

    (embed,eno) = opts.embed.split( ":" )
    eno = string.atoi( eno )

    (host,hno)  = opts.host.split( ":" )
    hno = string.atoi( hno )

    # read input
    # IO  filename  type  mode  options
    try:
      embedio = IO( embed, 'POSCAR', 'r', opts_sys )
      embedio.read()
    except:
      if self.debug:
        raise
      else:
        print "Input not found:", embedio
        sys.exit(1)
    # end try

    try:
      hostio = IO( host, 'POSCAR', 'r', opts_sys )
      hostio.read()
    except:
      if self.debug:
        raise
      else:
        print "Input not found:", host
        sys.exit(1)
    # end try

    host_geom = hostio.geom()
    #               where what
    # self = host
    host_geom.embed( hno, embedio.geom(), eno )
    host_geom.normalize()

    # write output
    # IO  filename  type  mode  options
    try:
      out = IO( opts.output, 'POSCAR', "w+", opts_sys )
      out.geom( host_geom )
      if opts.cart:
        out.write( { 'pt' : PT.Cart } )
      else:
        out.write( { 'pt' : PT.Direct } )
    except:
      if self.debug:
        raise
      else:
        print "Output failed:", opts.output
        sys.exit(1)
Пример #15
0
  def main( self ):
    (opts, args) = self.parse()

    width = 3
    sig   = opts.sigma
    amp   = opts.amp
    wsig  = width * sig

    sysopts = { "verbose" : self.verbose, "debug" : self.debug }
    try:
      inp = IO( opts.inp, 'UEIG', "r", sysopts )
      inp.read()
    except:
      if self.debug:
        raise
      else:
        print "Input failed:", opts.inp
        sys.exit(1)
    # end try

    mu = 0.0

    inp_ueig = inp.handler

    # grid for k-point: eig occ
    kp = opts.kp - 1
    sp = opts.sp - 1 
    inp_grid = inp_ueig.grid(kp,sp)
    # print inp_grid

    # create input fine grid
    low  = inp_ueig.grid_min(kp,sp) - wsig
    high = inp_ueig.grid_max(kp,sp) + wsig

    #print low, high
    rate = opts.rate
    grid_range = high - low
    maxrate = int(math.ceil( grid_range * rate ) )
    # print maxrate
    fine_range = np.arange( maxrate ) / float(maxrate)
    # print fine_range

    # shifted fine grid
    inp_fine_grid = fine_range * grid_range - abs( low )
    # print inp_fine_grid

    # compound grid
    inp_comp_grid = np.concatenate((inp_grid[:,0], inp_fine_grid))
    inp_comp_grid = np.sort(inp_comp_grid)
    # print inp_comp_grid

    # init grid: eig, fx,  d/dx fx
    inp_comp_grid = np.vstack( ( inp_comp_grid, 
                                 np.zeros( len( inp_comp_grid ) ), 
                                 np.zeros( len( inp_comp_grid ) ) ) )
    # print inp_comp_grid[0]
    # sys.exit(0)

    # generating DOS
    gendos( amp, sig, inp_grid, inp_comp_grid, opts.python )

    if opts.test:
      sys.exit(1)

    # output
    out_name = opts.out + "_kp_" + str(opts.kp) + "_sp_" + str(opts.sp)
    out = open( out_name , 'w')
    out.write( "" )

    i_range=len(inp_grid)
    j_range=len(inp_comp_grid[0])

    # create & write out dos
    dos = np.zeros( (j_range,3) )
    for j in range(0,j_range):
      dos[j,0] = inp_comp_grid[0,j]
      dos[j,1] = inp_comp_grid[1,j]
      dos[j,2] = inp_comp_grid[2,j]
      out.write( "%12.6f %12.6f %12.6f\n" % (dos[j,0],dos[j,1],dos[j,2]) )
    out.close()

    # dump dos
    save(dos,out_name)
    # plot
    plot(dos)