def test_exchangeSPSD_BrinkBoeker_off_diag(self):

        att = AttributeArgs.ForceArgs.Brink_Boeker
        self.force = switchMatrixElementType(ForceEnum.Brink_Boeker)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            BrinkBoekerParameters.mu_length: {
                att.part_1: 0.6,
                att.part_2: 1.2
            },
            BrinkBoekerParameters.Wigner: {
                att.part_1: 100,
                att.part_2: -50
            },
            BrinkBoekerParameters.Majorana: {
                att.part_1: -50,
                att.part_2: -50
            },
            BrinkBoekerParameters.Heisenberg: {
                att.part_1: -50,
                att.part_2: -50
            },
            BrinkBoekerParameters.Bartlett: {
                att.part_1: 100,
                att.part_2: -50
            }
        }

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['P'],
            *valenceSpacesDict['SD']
        ])
        self._evaluateSingleParticleStates(sts)
    def test_paritySPSD_BrinkBoeker_diagonal(self):

        self.force = switchMatrixElementType(ForceEnum.Brink_Boeker)
        att = AttributeArgs.ForceArgs.Brink_Boeker
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            BrinkBoekerParameters.mu_length: {
                att.part_1: 0.6,
                att.part_2: 1.2
            },
            BrinkBoekerParameters.Wigner: {
                att.part_1: 100,
                att.part_2: -50
            },
            BrinkBoekerParameters.Majorana: {
                att.part_1: -50,
                att.part_2: -50
            },
            BrinkBoekerParameters.Heisenberg: {
                att.part_1: -50,
                att.part_2: -50
            },
            BrinkBoekerParameters.Bartlett: {
                att.part_1: 100,
                att.part_2: -50
            }
        }

        for shell in ('S', 'P', 'SD'):
            sts = tuple([*valenceSpacesDict[shell]])
            self._evaluateParityConservationOfMatrixElements(sts)
    def run(self):
        """
        Calculate all the matrix elements for all the interactions, and 
        print its combination in a file.
        """
        self._defineValenceSpaceEnergies()
        self._sortQQNNFromTheValenceSpace()
        self._checkHamilTypeAndForces()

        _forcesAttr = ip.Force_Parameters
        times_ = {}
        for force, force_list in getattr(self.input_obj, _forcesAttr).items():
            i = 0
            for params in force_list:
                force_str = force + str(i) if len(force_list) > 1 else force
                # update arrays and variables
                i += 1
                self.results = {}
                self._forceNameFromForceEnum[force_str] = force
                tic_ = time.time()
                if force == ForceEnum.Force_From_File:
                    ## read from file case
                    self._readMatrixElementsFromFile(force_str, **params)
                    times_[force_str] = round(time.time() - tic_, 4)
                    continue
                ## computable interaction
                try:
                    sho_params = getattr(self.input_obj, ip.SHO_Parameters)

                    self.tbme_class = switchMatrixElementType(force)
                    self.tbme_class.resetInteractionParameters(also_SHO=True)
                    self.tbme_class.setInteractionParameters(
                        **params, **sho_params)
                    self._computeForValenceSpace(force)

                    self.resultsByInteraction[force_str] = deepcopy(
                        self.results)
                    times_[force_str] = round(time.time() - tic_, 4)
                    print(" Force [{}] m.e. calculated: [{}]s".format(
                        force, times_[force_str]))
                except BaseException:
                    trace = traceback.format_exc()
                    self._procedureToSkipBrokenInteraction(force_str, trace)

        print("Finished computation, Total time (s): [", sum(times_.values()),
              "]=")
        print("\n".join(["\t" + str(t) + "s" for t in times_.items()]))
        if len(self._brokeInteractions) > 0:
            print(
                _LINE_1, "ERROR !! Interactions have errors"
                " and where skipped with these exceptions")
            for f, excep in self._brokeInteractions.items():
                print("Interaction [{}], Exception ::\n{}\n{}".format(
                    f, excep, _LINE_2))

        self.combineAllResults()
        self.printMatrixElementsFile()
        self.printComMatrixElements()
    def test_paritySPSD_ShortRangeLS_diagonal(self):
        self.force = switchMatrixElementType(ForceEnum.SpinOrbitShortRange)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            CentralMEParameters.constant: 1,
            CentralMEParameters.potential: PotentialForms.Power,
            CentralMEParameters.mu_length: 1
        }

        for shell in ('S', 'P', 'SD'):
            sts = tuple([*valenceSpacesDict[shell]])
            self._evaluateParityConservationOfMatrixElements(sts)
    def test_exchangeSPSD_ShortRangeLS_diagonal(self):

        self.force = switchMatrixElementType(ForceEnum.SpinOrbitShortRange)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            CentralMEParameters.constant: 1,
            CentralMEParameters.potential: PotentialForms.Power,
            CentralMEParameters.mu_length: 1
        }

        for shell in ('S', 'P', 'SD'):
            spss = tuple([*valenceSpacesDict[shell]])
            self._evaluateSingleParticleStates(spss)
    def test_exchangeSPSD_Kinetic2Body(self):

        self.force = switchMatrixElementType(ForceEnum.Kinetic_2Body)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            SHO_Parameters.A_Mass: 8
        }

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['PF'],
            *valenceSpacesDict['SD']
        ])

        self._evaluateSingleParticleStates(sts)
    def test_paritySPSD_Kinetic2Body(self):

        self.force = switchMatrixElementType(ForceEnum.Kinetic_2Body)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            SHO_Parameters.A_Mass: 8
        }

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['PF'],
            *valenceSpacesDict['SD']
        ])

        self._evaluateParityConservationOfMatrixElements(sts)
    def test_paritySPSD_SpinOrbit(self):
        self.force = switchMatrixElementType(ForceEnum.SpinOrbit)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            CentralMEParameters.constant: 1,
            CentralMEParameters.potential: PotentialForms.Power,
            CentralMEParameters.mu_length: 1,
        }

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['P'],
            *valenceSpacesDict['SD']
        ])

        self._evaluateParityConservationOfMatrixElements(sts)
    def test_exchangeSPSD_ShortRangeLS_off_diag(self):

        self.force = switchMatrixElementType(ForceEnum.SpinOrbitShortRange)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            CentralMEParameters.constant: 1,
            CentralMEParameters.potential: PotentialForms.Power,
            CentralMEParameters.mu_length: 1
        }

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['P'],
            *valenceSpacesDict['SD']
        ])

        self._evaluateSingleParticleStates(sts)
    def test_exchangeSPSD_DensityDependant(self):

        self.force = switchMatrixElementType(ForceEnum.Density_Dependent)
        self.force_kwargs = {
            SHO_Parameters.b_length: 1,
            SHO_Parameters.A_Mass: 8,
            DensityDependentParameters.constant: 1,
            CentralMEParameters.potential: PotentialForms.Power,
            CentralMEParameters.mu_length: 1,
            DensityDependentParameters.alpha: 1 / 3,
            DensityDependentParameters.x0: 1,
        }

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['P'],
            *valenceSpacesDict['SD']
        ])

        self._evaluateSingleParticleStates(sts)
Ejemplo n.º 11
0
 def _setForces(self):
     """ Set the properties of the m.e. classes: 
         Explicit Antisymmetrization_, Scheme
     and instance the auxiliary lists to put the L/S quantum numbers, norms ...
     """
     _forcesAttr = ip.Force_Parameters
     sho_params = getattr(self.input_obj, ip.SHO_Parameters)
     
     for force, force_list in getattr(self.input_obj, _forcesAttr).items():
         if len(force_list) > 1:
             ## Verify forces do not repeat
             if force == ForceEnum.Force_From_File:
                 for i, params in enumerate(force_list):
                     force_str = force + str(i)
                     ## read from file case 
                     self._readMatrixElementsFromFile(force_str, **params)
                 continue ## skip the rest of the steps
             else:
                 raise TBME_SpdRunnerException("Cannot compute two times "
                     "the same interaction: [{}] len={}".format(force, 
                                                                len(force_list)))
         
         self.forces.append(switchMatrixElementType(force))
         ## define interactions
         self._allForcesAreLS *= self.forces[-1].RECOUPLES_LS
         self.forcesDict[force] = len(self.forces) - 1
         self.forces[-1].setInteractionParameters(**force_list[0], **sho_params)
         
         self.forcesIsAntisym.append(self.forces[-1].EXPLICIT_ANTISYMM)
         
         if self.forces[-1].COUPLING == CouplingSchemeEnum.JJ:
             self.forcesScheme.append(self._Scheme.J)
             dim_t = 6
         else:
             self.forcesScheme.append(self._Scheme.JT)
             dim_t = 2
         
         self.me_instances.append([None]*dim_t)
         self.valid_L_forKets.append([None]*dim_t)
         self.valid_S_forKets.append([None]*dim_t)
         self.forcesNorms.append([None]*dim_t)
    def testOrthonormalityOfMoshinskyTransformation(self):

        self.force = switchMatrixElementType(ForceEnum.Central)
        force_kwargs = {
            SHO_Parameters.b_length: 1.5,
            CentralMEParameters.mu_length: 0,
            CentralMEParameters.potential: PotentialForms.Power,
            CentralMEParameters.constant: 1.0,
            CentralMEParameters.n_power: 0
        }
        self.force.setInteractionParameters(**force_kwargs)

        sts = tuple([
            *valenceSpacesDict['S'], *valenceSpacesDict['P'],
            *valenceSpacesDict['SD'], *valenceSpacesDict['PF']
        ])

        for i in range(len(sts)):
            a = QN_1body_jj(*readAntoine(sts[i]))
            for j in range(i, len(sts)):
                b = QN_1body_jj(*readAntoine(sts[j]))
                for k in range(j, len(sts)):
                    c = QN_1body_jj(*readAntoine(sts[k]))
                    for l in range(k, len(sts)):
                        d = QN_1body_jj(*readAntoine(sts[l]))

                        self._testOrthogonality(a, b, c, d)

        if len(self.failures) > 0:
            print("FAILURES in Orthonormalization test:")
            for fail in self.failures:
                print(fail)
            self.assertEqual(
                len(self.failures), 0,
                "there are [{}] non orthogonal m.e (TOL={})".format(
                    len(self.failures), self.TOLERANCE))
    def _checkHamilTypeAndForces(self):
        """ 
        Certain interactions cannot be expressed in JT formalism if they break
        isospin_ symmetry (f.e Coulomb_). That means the global scheme for the
        matrix elements must be J-scheme, and then, only hamilType=3/4 are 
        accepted to print the elements.
        
        This method checks that if HamilType is 0/1, then it must not be any 
        isospin_ breaking interactions (before any calculations).
        
        Also fill the interaction schemes.
        If com correction, add to the 
        """

        _forcesAttr = ip.Force_Parameters
        J_schemeForces = []
        JT_schemeForces = []
        T_breaking = []
        self._forces2ReadFromFile = False

        for force in getattr(self.input_obj, _forcesAttr):

            me = switchMatrixElementType(force)

            if me._BREAK_ISOSPIN:  # cannot use property, m.e. not instanced
                T_breaking.append(force)

            f_scheme = me.COUPLING
            f_scheme = [
                f_scheme,
            ] if isinstance(f_scheme, str) else f_scheme

            if CouplingSchemeEnum.L in f_scheme or CouplingSchemeEnum.S in f_scheme:
                raise TBME_RunnerException(
                    "Matrix Element in L or S scheme,"
                    "class can only run in J or JT scheme")

            if (CouplingSchemeEnum.JJ in f_scheme):
                if force == ForceEnum.Force_From_File:
                    self._forces2ReadFromFile = True
                    continue
                elif force == ForceEnum.Kinetic_2Body:
                    print(self.__advertence_Kin2Body)
                    self._com_correction = True
                    continue

                if (CouplingSchemeEnum.T in f_scheme):
                    JT_schemeForces.append(force)
                    self.interactionSchemes[force] = self._Scheme.JT
                    if me._BREAK_ISOSPIN:
                        raise TBME_RunnerException(
                            "Error in force [{}] <class>:[{}] definition".
                            format(force, me.__class__.__name__) +
                            ", Isospin based (reduced) matrix elements breaks T."
                        )
                else:
                    J_schemeForces.append(force)
                    self.interactionSchemes[force] = self._Scheme.J

        if self._com_correction:
            # append the K 2Body to the input force to compute (remove after)
            getattr(self.input_obj,
                    _forcesAttr)[ForceEnum.Kinetic_2Body] = [dict()]
            JT_schemeForces.append(ForceEnum.Kinetic_2Body)
            self.interactionSchemes[ForceEnum.Kinetic_2Body] = self._Scheme.JT

        if self._hamil_type in '12':
            if len(T_breaking) > 0:
                raise TBME_RunnerException(
                    "Cannot compute isospin-breaking interactions"
                    "{} to write in hamilType format 1-2 (JT scheme)".format(
                        T_breaking))
            if len(JT_schemeForces) == 0 and (not self._forces2ReadFromFile):
                # TODO: might convert to JT scheme J forces.
                raise TBME_RunnerException("Cannot compute J forces JT scheme")