def __init__(self, mode=KSamplingModes.monkhorst, num_kpts= 0,
                 kpts=((1, 1, 1),),
                 kpt_shifts=(0.5, 0.5, 0.5),
                 kpts_weights=None, use_symmetries=True, use_time_reversal=True, chksymbreak=None,
                 comment=None):
        """
        Highly flexible constructor for KSampling objects.  The flexibility comes
        at the cost of usability and in general, it is recommended that you use
        the default constructor only if you know exactly what you are doing and
        requires the flexibility.  For most usage cases, the object be constructed
        far more easily using the convenience static constructors:

            #. gamma_only
            #. gamma_centered
            #. monkhorst
            #. monkhorst_automatic
            #. path

        and it is recommended that you use those.

        Args:
            mode: Mode for generating k-poits. Use one of the KSamplingModes enum types.
            num_kpts: Number of kpoints if mode is "automatic"
                Number of division for the sampling of the smallest segment if mode is "path".
                Not used for the other modes
            kpts: Number of divisions. Even when only a single specification is
                  required, e.g. in the automatic scheme, the kpts should still
                  be specified as a 2D array. e.g., [[20]] or [[2,2,2]].
            kpt_shifts: Shifts for Kpoints.
            use_symmetries: False if spatial symmetries should not be used
                to reduce the number of independent k-points.
            use_time_reversal: False if time-reversal symmetry should not be used
                to reduce the number of independent k-points.
            kpts_weights: Optional weights for kpoints. For explicit kpoints.
            chksymbreak: Abinit input variable: check whether the BZ sampling preserves the symmetry of the crystal.
            comment: String comment for Kpoints

        .. note::
            The default behavior of the constructor is monkhorst.
        """
        if isinstance(mode, str):
            mode = KSamplingModes[mode]

        super().__init__()

        self.mode = mode
        self.comment = comment

        self.num_kpts = num_kpts
        self.kpts = kpts
        self.kpt_shifts = kpt_shifts
        self.kpts_weights = kpts_weights
        self.use_symmetries = use_symmetries
        self.use_time_reversal = use_time_reversal
        self.chksymbreak = chksymbreak

        abivars = {}

        if mode == KSamplingModes.monkhorst:
            assert num_kpts == 0
            ngkpt  = np.reshape(kpts, 3)
            shiftk = np.reshape(kpt_shifts, (-1,3))

            if use_symmetries and use_time_reversal: kptopt = 1
            if not use_symmetries and use_time_reversal: kptopt = 2
            if not use_symmetries and not use_time_reversal: kptopt = 3
            if use_symmetries and not use_time_reversal: kptopt = 4

            abivars.update({
                "ngkpt"      : ngkpt,
                "shiftk"     : shiftk,
                "nshiftk"    : len(shiftk),
                "kptopt"     : kptopt,
                "chksymbreak": chksymbreak,
            })

        elif mode == KSamplingModes.path:
            if num_kpts <= 0:
                raise ValueError("For Path mode, num_kpts must be specified and >0")

            kptbounds = np.reshape(kpts, (-1,3))
            #print("in path with kptbound: %s " % kptbounds)

            abivars.update({
                "ndivsm"   : num_kpts,
                "kptbounds": kptbounds,
                "kptopt"   : -len(kptbounds)+1,
            })

        elif mode == KSamplingModes.automatic:
            kpts = np.reshape(kpts, (-1,3))
            if len(kpts) != num_kpts:
                raise ValueError("For Automatic mode, num_kpts must be specified.")

            abivars.update({
                "kptopt"     : 0,
                "kpt"        : kpts,
                "nkpt"       : num_kpts,
                "kptnrm"     : np.ones(num_kpts),
                "wtk"        : kpts_weights,  # for iscf/=-2, wtk.
                "chksymbreak": chksymbreak,
            })

        else:
            raise ValueError("Unknown mode %s" % mode)

        self.abivars = abivars
def __init__ ( self , mode = KSamplingModes . monkhorst , num_kpts = 0 , kpts = ( ( 1 , 1 , 1 ) , ) , kpt_shifts = ( 0.5 , 0.5 , 0.5 ) , kpts_weights = None , use_symmetries = True , use_time_reversal = True , chksymbreak = None , comment = None ) : if isinstance ( mode , str ) : mode = KSamplingModes [ mode ] super ( ) . __init__ ( ) self . mode = mode self . comment = comment self . num_kpts = num_kpts self . kpts = kpts self . kpt_shifts = kpt_shifts self . kpts_weights = kpts_weights self . use_symmetries = use_symmetries self . use_time_reversal = use_time_reversal self . chksymbreak = chksymbreak abivars = { } if mode == KSamplingModes . monkhorst : assert num_kpts == 0 ngkpt = np . reshape ( kpts , 3 ) shiftk = np . reshape ( kpt_shifts , ( - 1 , 3 ) ) if use_symmetries and use_time_reversal : kptopt = 1 if not use_symmetries and use_time_reversal : kptopt = 2 if not use_symmetries and not use_time_reversal : kptopt = 3 if use_symmetries and not use_time_reversal : kptopt = 4 abivars . update ( { "ngkpt" : ngkpt , "shiftk" : shiftk , "nshiftk" : len ( shiftk ) , "kptopt" : kptopt , "chksymbreak" : chksymbreak , } ) elif mode == KSamplingModes . path : if num_kpts <= 0 : raise ValueError ( "For Path mode, num_kpts must be specified and >0" ) kptbounds = np . reshape ( kpts , ( - 1 , 3 ) ) abivars . update ( { "ndivsm" : num_kpts , "kptbounds" : kptbounds , "kptopt" : - len ( kptbounds ) + 1 , } ) elif mode == KSamplingModes . automatic : kpts = np . reshape ( kpts , ( - 1 , 3 ) ) if len ( kpts ) != num_kpts : raise ValueError ( "For Automatic mode, num_kpts must be specified." ) abivars . update ( { "kptopt" : 0 , "kpt" : kpts , "nkpt" : num_kpts , "kptnrm" : np . ones ( num_kpts ) , "wtk" : kpts_weights , "chksymbreak" : chksymbreak , } ) else : raise ValueError ( "Unknown mode %s" % mode ) self . abivars = abivars
Highly flexible constructor for KSampling objects.  The flexibility comes
        at the cost of usability and in general, it is recommended that you use
        the default constructor only if you know exactly what you are doing and
        requires the flexibility.  For most usage cases, the object be constructed
        far more easily using the convenience static constructors:

            #. gamma_only
            #. gamma_centered
            #. monkhorst
            #. monkhorst_automatic
            #. path

        and it is recommended that you use those.

        Args:
            mode: Mode for generating k-poits. Use one of the KSamplingModes enum types.
            num_kpts: Number of kpoints if mode is "automatic"
                Number of division for the sampling of the smallest segment if mode is "path".
                Not used for the other modes
            kpts: Number of divisions. Even when only a single specification is
                  required, e.g. in the automatic scheme, the kpts should still
                  be specified as a 2D array. e.g., [[20]] or [[2,2,2]].
            kpt_shifts: Shifts for Kpoints.
            use_symmetries: False if spatial symmetries should not be used
                to reduce the number of independent k-points.
            use_time_reversal: False if time-reversal symmetry should not be used
                to reduce the number of independent k-points.
            kpts_weights: Optional weights for kpoints. For explicit kpoints.
            chksymbreak: Abinit input variable: check whether the BZ sampling preserves the symmetry of the crystal.
            comment: String comment for Kpoints

        .. note::
            The default behavior of the constructor is monkhorst.