Пример #1
0
 def test_to_dict_from_dict(self):
     k = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
     d = k.to_dict
     k2 = Kpoints.from_dict(d)
     self.assertEqual(k.kpts, k2.kpts)
     self.assertEqual(k.style, k2.style)
     self.assertEqual(k.kpts_shift, k2.kpts_shift)
Пример #2
0
 def test_static_constructors(self):
     kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
     self.assertEqual(kpoints.style, "Gamma")
     self.assertEqual(kpoints.kpts, [[3, 3, 3]])
     kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
     self.assertEqual(kpoints.style, "Monkhorst")
     self.assertEqual(kpoints.kpts, [[2, 2, 2]])
     kpoints = Kpoints.automatic(100)
     self.assertEqual(kpoints.style, "Automatic")
     self.assertEqual(kpoints.kpts, [[100]])
     filepath = os.path.join(test_dir, 'POSCAR')
     poscar = Poscar.from_file(filepath)
     kpoints = Kpoints.automatic_density(poscar.struct, 500)
     self.assertEqual(kpoints.kpts, [[2, 4, 4]])
Пример #3
0
    def _vasp_kpoints_setup(self):
        """Parse mast_kpoints string, which should take the format:
            number, number, number designation
            examples: "3x3x3 M", "1x1x1 G". If no designation is given,
            Monkhorst-Pack is assumed.
        """
        name = self.keywords['name']
        tryname = os.path.join(name, "KPOINTS")
        if os.path.isfile(tryname):
            #KPOINTS already exists. Do not overwrite.
            my_kpoints = Kpoints.from_file(tryname)
            return my_kpoints
        if not (self.metafile.read_data('kpoints')==None):
            kpoints = self.metafile.read_data('kpoints').split()
            kmesh = (int(kpoints[0].split('x')[0]),int(kpoints[0].split('x')[1]),int(kpoints[0].split('x')[2]))
            try: desig = kpoints[1].upper()
            except IndexError: desig = 'M'
            try: kshift = (float(kpoints[2]),float(kpoints[3]),float(kpoints[4]))
            except IndexError: kshift = (0.0,0.0,0.0)
        else:
            if 'mast_kpoints' in self.keywords['program_keys'].keys():
                kpoints = self.keywords['program_keys']['mast_kpoints']
            else:
                raise MASTError(self.__class__.__name__,"k-point instructions need to be set either in ingredients keyword mast_kpoints or scaling section in structure ingredient: No k-point settings for the ingredient %s"% name)
            if len(kpoints) == 3:
                desig = "M"
            elif 'line' in str(kpoints[1]):
                desig = 'L'
            else:
                desig = kpoints[3].upper()
            if not desig == 'L':
                kmesh = (int(kpoints[0]),int(kpoints[1]),int(kpoints[2]))
                kshift = (0,0,0)
        if desig == "M":
            my_kpoints = Kpoints.monkhorst_automatic(kpts=kmesh,shift=kshift)
        elif desig == "G":
            my_kpoints = Kpoints.gamma_automatic(kpts=kmesh,shift=kshift)
        elif desig == 'L':
            my_kpoints='Line Mode\n'+'\n'.join(' '.join(kpoints).split(','))+'\n'
            fp=open(name+'/KPOINTS','w')
            fp.write(my_kpoints)
        else:
            raise MASTError(self.__class__.__name__,"kpoint designation " + desig + " not recognized.")

        dirutil.lock_directory(name)
        if not desig=='L':
            my_kpoints.write_file(name + "/KPOINTS")
        dirutil.unlock_directory(name)
        return my_kpoints