From c676a40e69d55f66b7937036cf10f4a02d308804 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Thu, 14 Nov 2024 22:53:13 -0800 Subject: [PATCH] types: unindent class definition --- src/pymcnp/files/inp/datum/factory.py | 8 +- .../inp/datum/particle_physics_options.py | 16 ++-- src/pymcnp/files/utils/types.py | 93 ++++++++++--------- 3 files changed, 59 insertions(+), 58 deletions(-) diff --git a/src/pymcnp/files/inp/datum/factory.py b/src/pymcnp/files/inp/datum/factory.py index 6578534..abc8eaa 100644 --- a/src/pymcnp/files/inp/datum/factory.py +++ b/src/pymcnp/files/inp/datum/factory.py @@ -405,7 +405,7 @@ def create_datum_from_mcnp(source: str, line: types.McnpInteger = None): raise errors.MCNPSyntaxError(errors.MCNPSyntaxCodes.TOOMANY_DATUM_PHYS) match designator.particles[0]: - case types.Designator.Particle.NEUTRON: + case types.Particle.NEUTRON: emax = types.McnpReal.from_mcnp(tokens.popl()) emcnf = types.McnpReal.from_mcnp(tokens.popl()) iunr = types.McnpInteger.from_mcnp(tokens.popl()) @@ -436,7 +436,7 @@ def create_datum_from_mcnp(source: str, line: types.McnpInteger = None): i_els_model, ) - case types.Designator.Particle.PHOTON: + case types.Particle.PHOTON: emcpf = types.McnpReal.from_mcnp(tokens.popl()) ides = types.McnpInteger.from_mcnp(tokens.popl()) nocoh = types.McnpInteger.from_mcnp(tokens.popl()) @@ -448,7 +448,7 @@ def create_datum_from_mcnp(source: str, line: types.McnpInteger = None): parameters = (emcpf, ides, nocoh, ispn, nodop, fism) - case types.Designator.Particle.ELECTRON: + case types.Particle.ELECTRON: emax = types.McnpReal.from_mcnp(tokens.popl()) ides = types.McnpInteger.from_mcnp(tokens.popl()) ibad = types.McnpInteger.from_mcnp(tokens.popl()) @@ -483,7 +483,7 @@ def create_datum_from_mcnp(source: str, line: types.McnpInteger = None): ckvnum, ) - case types.Designator.Particle.PROTON: + case types.Particle.PROTON: emax = types.McnpReal.from_mcnp(tokens.popl()) ean = types.McnpReal.from_mcnp(tokens.popl()) tabl = types.McnpReal.from_mcnp(tokens.popl()) diff --git a/src/pymcnp/files/inp/datum/particle_physics_options.py b/src/pymcnp/files/inp/datum/particle_physics_options.py index 75dac26..449ad55 100644 --- a/src/pymcnp/files/inp/datum/particle_physics_options.py +++ b/src/pymcnp/files/inp/datum/particle_physics_options.py @@ -36,13 +36,13 @@ def __init__(self, designator: types.Designator, parameters: tuple[any]): raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_PARAMETERS) match designator: - case types.Designator.Particle.NEUTRON: + case types.Particle.NEUTRON: obj = ParticlePhysicsOptionsNeutron(*parameters) - case types.Designator.Particle.PHOTON: + case types.Particle.PHOTON: obj = ParticlePhysicsOptionsPhoton(*parameters) - case types.Designator.Particle.ELECTRON: + case types.Particle.ELECTRON: obj = ParticlePhysicsOptionsElectron(*parameters) - case types.Designator.Particle.PROTON: + case types.Particle.PROTON: obj = ParticlePhysicsOptionsProton(*parameters) case _: obj = ParticlePhysicsOptionsOther(designator, *parameters) @@ -140,7 +140,7 @@ def __init__( i_int_model, i_els_model, ) - self.designator = types.Designator.Particle.NEUTRON + self.designator = types.Particle.NEUTRON self.emax = emax self.emcnf = emcnf @@ -215,7 +215,7 @@ def __init__( _card.Card.__init__(self, 'phys:p') self.mnemonic = DatumMnemonic.PARTICLE_PHYSICS_OPTIONS self.parameters = (emcpf, ides, nocoh, ispn, nodop, fism) - self.designator = types.Designator.Particle.PHOTON + self.designator = types.Particle.PHOTON self.emcpf = emcpf self.ides = ides @@ -348,7 +348,7 @@ def __init__( electron_method_boundary, ckvnum, ) - self.designator = types.Designator.Particle.ELECTRON + self.designator = types.Particle.ELECTRON self.emax = emax self.ides = ides @@ -471,7 +471,7 @@ def __init__( ckvnum, drp, ) - self.designator = types.Designator.Particle.PROTON + self.designator = types.Particle.PROTON self.emax = emax self.ean = ean diff --git a/src/pymcnp/files/utils/types.py b/src/pymcnp/files/utils/types.py index d805bef..fc081a4 100644 --- a/src/pymcnp/files/utils/types.py +++ b/src/pymcnp/files/utils/types.py @@ -160,6 +160,50 @@ def __str__(self): return self.to_mcnp() +class Particle(str, enum.Enum): + """ + ``Particle`` represents individular particle designators. + """ + + NEUTRON = 'n' + ANTI_NEUTRON = 'q' + PHOTON = 'p' + ELECTRON = 'e' + POSITRON = 'f' + NEGATIVE_MUON = '|' + POSITIVE_MUON = '!' + ELECTRON_NEUTRINO = 'u' + ANTI_ELECTRON_NEUTRINO = '<' + MUON_NEUTRINO = 'v' + ANTI_MUON_MEUTRINO = '>' + PROTON = 'h' + ANTI_PROTON = 'g' + LAMBDA_BARYON = 'l' + ANTI_LAMBDA_BARYON = 'b' + POSITIVE_SIGMA_BARYON = '+' + ANTI_POSITIVE_SIGMA_BARYON = '_' + NEGATIVE_SIGMA_BARYON = '-' + ANTI_NEGATIVE_SIGMA_BARYON = '~' + CASCADE = 'x' + ANTI_CASCADE = 'c' + NEGATIVE_CASCADE = 'y' + POSITIVE_CASCADE = 'w' + OMEGA_BARYON = 'o' + ANTI_OMEGA_BARYON = '@' + POSITIVE_PION = '/' + NEGATIVE_PION = '*' + NEUTRAL_PION = 'z' + POSITIVE_KAON = 'k' + NEGATIVE_KAON = '?' + SHORT_KAON = '%' + LONG_KAON = '^' + DEUTERON = 'd' + TRITON = 't' + HELION = 's' + ALPHA = 'a' + HEAVY_IONS = '#' + + class Designator: """ ``Designator`` represents MCNP particle designators. @@ -168,49 +212,6 @@ class Designator: particles: Tuple of particles. """ - class Particle(str, enum.Enum): - """ - ``Particle`` represents individular particle designators. - """ - - NEUTRON = 'n' - ANTI_NEUTRON = 'q' - PHOTON = 'p' - ELECTRON = 'e' - POSITRON = 'f' - NEGATIVE_MUON = '|' - POSITIVE_MUON = '!' - ELECTRON_NEUTRINO = 'u' - ANTI_ELECTRON_NEUTRINO = '<' - MUON_NEUTRINO = 'v' - ANTI_MUON_MEUTRINO = '>' - PROTON = 'h' - ANTI_PROTON = 'g' - LAMBDA_BARYON = 'l' - ANTI_LAMBDA_BARYON = 'b' - POSITIVE_SIGMA_BARYON = '+' - ANTI_POSITIVE_SIGMA_BARYON = '_' - NEGATIVE_SIGMA_BARYON = '-' - ANTI_NEGATIVE_SIGMA_BARYON = '~' - CASCADE = 'x' - ANTI_CASCADE = 'c' - NEGATIVE_CASCADE = 'y' - POSITIVE_CASCADE = 'w' - OMEGA_BARYON = 'o' - ANTI_OMEGA_BARYON = '@' - POSITIVE_PION = '/' - NEGATIVE_PION = '*' - NEUTRAL_PION = 'z' - POSITIVE_KAON = 'k' - NEGATIVE_KAON = '?' - SHORT_KAON = '%' - LONG_KAON = '^' - DEUTERON = 'd' - TRITON = 't' - HELION = 's' - ALPHA = 'a' - HEAVY_IONS = '#' - def __init__(self, particles: tuple[Particle]): """ ``__init__`` initializes ``Designator``. @@ -234,7 +235,7 @@ def __init__(self, particles: tuple[Particle]): info=str(particles), ) - self.particles: Final[tuple[Designator.Particle]] = particles + self.particles: Final[tuple[Particle]] = particles @staticmethod def from_mcnp(source: str): @@ -253,7 +254,7 @@ def from_mcnp(source: str): """ try: - particles = tuple([Designator.Particle(token) for token in source.split(',')]) + particles = tuple([Particle(token) for token in source.split(',')]) except ValueError: raise errors.MCNPSemanticError( errors.MCNPSemanticCodes.INVALID_MCNP_DESIGNATOR, info=source @@ -272,7 +273,7 @@ def to_mcnp(self) -> str: INP string for ``Designator`` object. """ - return ','.join(Designator.Particle(particle) for particle in self.particles) + return ','.join(Particle(particle) for particle in self.particles) def __eq__(self, other): return self.particles == other.particles