Skip to content

Commit

Permalink
types: unindent class definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun Persaud committed Nov 15, 2024
1 parent 379af71 commit c676a40
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 58 deletions.
8 changes: 4 additions & 4 deletions src/pymcnp/files/inp/datum/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
16 changes: 8 additions & 8 deletions src/pymcnp/files/inp/datum/particle_physics_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
93 changes: 47 additions & 46 deletions src/pymcnp/files/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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``.
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c676a40

Please sign in to comment.