def convert_file(self):
     
     try:
         magres_file = open(self.file_name.get()).read()
     except IOError:
         self.status_msg.set("ERROR: Couldn't load input file")
         return
     
     try:
         castep_file = open(self.castep_file_name.get()).read()
     except IOError:
         castep_file = None
         
     try:
         out_file = open(self.out_file_name.get(), 'w')
     except IOError:
         self.status_msg.set("ERROR: Couldn't create output file")
         return
     
     oldmagres_file = OldMagres(magres_file, castep_file)
     
     out = oldmagres_file.as_new_format()
     
     out_file.write(str(out))
     
     if castep_file is not None:
         self.status_msg.set("Conversion successfully completed")
     else:
         self.status_msg.set("Conversion successfully completed but .castep file was not found")
Esempio n. 2
0
    def convert_file(self):

        try:
            magres_file = open(self.file_name.get()).read()
        except IOError:
            self.status_msg.set("ERROR: Couldn't load input file")
            return

        try:
            castep_file = open(self.castep_file_name.get()).read()
        except IOError:
            castep_file = None

        try:
            out_file = open(self.out_file_name.get(), 'w')
        except IOError:
            self.status_msg.set("ERROR: Couldn't create output file")
            return

        oldmagres_file = OldMagres(magres_file, castep_file)

        out = oldmagres_file.as_new_format()

        out_file.write(str(out))

        if castep_file is not None:
            self.status_msg.set("Conversion successfully completed")
        else:
            self.status_msg.set(
                "Conversion successfully completed but .castep file was not found"
            )
Esempio n. 3
0
  def load(self, include=None, exclude=None):
    if include is None:
      include = set(["cell", "params", "magres", "bonds"])
    else:
      include = set(include)

    if exclude is None:
      exclude = set()
    else:
      exclude = set(exclude)

    to_load = include - exclude

    if hasattr(self, 'cell_file') and "cell" in to_load:
      self.cell = Cell(self.cell_file)

    if hasattr(self, 'param_file') and "params" in to_load:
      self.params = Parameters(self.param_file)

    if hasattr(self, 'magres_file') and "magres" in to_load:
      self.magres = MagresResult(self.magres_file)

      # Nothing there? Try using the old-style parser
      if self.magres.magres_file.data_dict == {}:
        old_magres_file = OldMagres(self.magres_file, self.castep_file)
        #self.magres_file.data_dict = old_magres_file.as_new_format()
        self.magres.magres_file = old_magres_file.as_new_format()

        print self.magres

    if hasattr(self, 'castep_file') and "bonds" in to_load:
        try:
          bonds.add_bonds(self.cell.ions, self.castep_file)
        except:
          pass

    if hasattr(self, 'castep_file') and "energy" in to_load:
      try:
        self.energy = energy.parse(self.castep_file)
      except energy.CantFindEnergy:
        self.energy = None

      self.scf = energy.SCFResult.load(self.castep_file)

    if hasattr(self, 'castep_file') and "mulliken" in to_load:
      self.mulliken = mulliken.MullikenResult.load(self.castep_file)
Esempio n. 4
0
    def load(self, include=None, exclude=None):
        if include is None:
            include = set(["cell", "params", "magres", "bonds"])
        else:
            include = set(include)

        if exclude is None:
            exclude = set()
        else:
            exclude = set(exclude)

        to_load = include - exclude

        if hasattr(self, 'cell_file') and "cell" in to_load:
            self.cell = Cell(self.cell_file)

        if hasattr(self, 'param_file') and "params" in to_load:
            self.params = Parameters(self.param_file)

        if hasattr(self, 'magres_file') and "magres" in to_load:
            self.magres = MagresResult(self.magres_file)

            # Nothing there? Try using the old-style parser
            if self.magres.magres_file.data_dict == {}:
                old_magres_file = OldMagres(self.magres_file, self.castep_file)
                #self.magres_file.data_dict = old_magres_file.as_new_format()
                self.magres.magres_file = old_magres_file.as_new_format()

                print self.magres

        if hasattr(self, 'castep_file') and "bonds" in to_load:
            try:
                bonds.add_bonds(self.cell.ions, self.castep_file)
            except:
                pass

        if hasattr(self, 'castep_file') and "energy" in to_load:
            try:
                self.energy = energy.parse(self.castep_file)
            except energy.CantFindEnergy:
                self.energy = None

            self.scf = energy.SCFResult.load(self.castep_file)

        if hasattr(self, 'castep_file') and "mulliken" in to_load:
            self.mulliken = mulliken.MullikenResult.load(self.castep_file)
Esempio n. 5
0
    magres_file = None
    castep_file = None

    if len(sys.argv) >= 2:
        try:
            magres_file = open(sys.argv[1]).read()
        except IOError:
            print("Could not load magres file '%s'" % sys.argv[1],
                  file=sys.stderr)
            sys.exit(1)

    if len(sys.argv) >= 3:
        try:
            castep_file = open(sys.argv[2]).read()
        except IOError:
            print("Could not load castep output file '%s'" % sys.argv[2],
                  file=sys.stderr)
            sys.exit(1)

    if castep_file is None:
        print(
            "WARNING: You have not supplied a .castep file as the second argument, so I don't know the crystal "
            "lattice.",
            file=sys.stderr)

    if magres_file is not None:
        oldmagres_file = OldMagres(magres_file, castep_file)

        magres_file = oldmagres_file.as_new_format()
        print(magres_file)
import numpy

from magres.oldmagres import OldMagres

if __name__ == "__main__":
  magres_file = None
  castep_file = None

  if len(sys.argv) >= 2:
    try:
      magres_file = open(sys.argv[1]).read()
    except IOError:
      print >>sys.stderr, "Could not load magres file '%s'" % sys.argv[1]
      sys.exit(1)

  if len(sys.argv) >= 3:
    try:
      castep_file = open(sys.argv[2]).read()
    except IOError:
      print >>sys.stderr, "Could not load castep output file '%s'" % sys.argv[2]
      sys.exit(1)

  if castep_file is None:
    print >>sys.stderr, "WARNING: You have not supplied a .castep file as the second argument, so I don't know the crystal lattice."

  if magres_file is not None:
    oldmagres_file = OldMagres(magres_file, castep_file)

    magres_file = oldmagres_file.as_new_format()
    print magres_file