Skip to content

Commit

Permalink
Merge branch '39-v20-examples' of github.com:lanl/PLEIADES into 39-v2…
Browse files Browse the repository at this point in the history
…0-examples
  • Loading branch information
alexmlongLANL committed Feb 22, 2025
2 parents b0d97d8 + 75f9c51 commit 2599a4f
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 96 deletions.
6 changes: 3 additions & 3 deletions docs/repo.map
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PLEIADES
| ├── __init__.py
| ├── factory.py
| ├── parfile.py
| ├── backends/
| ├── backends/
| │ ├── nova_ornl.py
| │ ├── __init__.py
| │ ├── local.py
Expand Down Expand Up @@ -65,7 +65,7 @@ PLEIADES
│ │ └── conftest.py
│ └── data/
│ ├── config
│ └── ex012
│ └── ex012
└── notebook/
├── sammy.param/
│ └── example.ipynb
Expand All @@ -74,4 +74,4 @@ PLEIADES
│ ├── ex012.ipynb
│ └── ex012a.par
└── ex027/
└── ex027a.endf
└── ex027a.endf
3 changes: 0 additions & 3 deletions notebook/samexm/ex012/ex012a.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"metadata": {},
"outputs": [],
"source": [
"import pathlib # Importing pathlib to work with file system paths\n",
"import tempfile # Importing tempfile to create temporary files and directories\n",
"\n",
"# Importing specific classes from the pleiades.sammy module\n",
"from pleiades.sammy.parfile import SammyParameterFile"
]
Expand Down
6 changes: 3 additions & 3 deletions notebook/samexm/ex012/ex012a.par
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@
10934820.00 1.2000E+03 2.7611E+05 0 0 0 23
15050371.00 1.2000E+03 6.3499E+05 0 0 0 23
25004488.00 1.2000E+03 6.9186E+03 0 0 0 23

0.1

RADIUS PARAMETERS FOLLOW
4.13642 4.13642 0-1 1 4 5
4.94372 4.94372 0-1 2 3 6 7
4.40000 4.40000 0-1 8 91011121314151617
4.20000 4.20000 0-11819202122
4.20000 4.20000 0-123242526272829

ISOTOPIC MASSES AND ABUNDANCES FOLLOW
27.976929 1.0000000 .9200 1 1 2 3 4 5 6 7
28.976496 .0467000 .0500 1 8 91011121314151617
Expand Down
6 changes: 3 additions & 3 deletions src/pleiades/sammy/notes/parfile_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
- Parameters:
- header: str
- Returns: Type[BaseModel]
- from_string
- from_string
@classmethod
- Parameters:
- data: str
Expand All @@ -72,7 +72,7 @@
- Parameters:
- card_name: str
- Returns: Type[BaseModel]
- from_file
- from_file
@classmethod
- Parameters:
- file_path: Union[str, pathlib.Path]
Expand All @@ -85,4 +85,4 @@
- None

## Main Function
- Example usage
- Example usage
39 changes: 20 additions & 19 deletions src/pleiades/sammy/parameters/isotope.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Masses must be > 0
- Spin groups must be valid for the model
"""

import os
from typing import List, Optional

Expand All @@ -54,25 +55,25 @@
from pleiades.utils.logger import Logger, _log_and_raise_error

# Initialize logger with file logging
log_file_path = os.path.join(os.getcwd(), 'pleiades-par.log')
log_file_path = os.path.join(os.getcwd(), "pleiades-par.log")
logger = Logger(__name__, log_file=log_file_path)

# Format definitions for standard format (<99 spin groups)
# Each numeric field has specific width requirements
FORMAT_STANDARD = {
"mass": slice(0, 10), # AMUISO: Atomic mass (amu)
"abundance": slice(10, 20), # PARISO: Fractional abundance
"uncertainty": slice(20, 30), # DELISO: Uncertainty on abundance
"flag": slice(30, 32), # IFLISO: Treatment flag
"mass": slice(0, 10), # AMUISO: Atomic mass (amu)
"abundance": slice(10, 20), # PARISO: Fractional abundance
"uncertainty": slice(20, 30), # DELISO: Uncertainty on abundance
"flag": slice(30, 32), # IFLISO: Treatment flag
}

# Spin group number positions
# Standard format: 2 columns per group starting at col 33
SPIN_GROUP_STANDARD = {
"width": 2, # Character width of each group number
"start": 32, # Start of first group
"per_line": 24, # Max groups per line
"cont_marker": slice(78, 80), # "-1" indicates continuation
"width": 2, # Character width of each group number
"start": 32, # Start of first group
"per_line": 24, # Max groups per line
"cont_marker": slice(78, 80), # "-1" indicates continuation
}

# Format for extended format (>99 spin groups)
Expand Down Expand Up @@ -140,7 +141,7 @@ def validate_groups(self) -> "IsotopeParameters":

for group in self.spin_groups:
if group == 0:
_log_and_raise_error(logger, f"Spin group number cannot be 0",ValueError)
_log_and_raise_error(logger, "Spin group number cannot be 0", ValueError)

# Check if we need extended format
if abs(group) > max_standard:
Expand Down Expand Up @@ -179,8 +180,8 @@ def from_lines(cls, lines: List[str], extended: bool = False) -> "IsotopeParamet
if not lines or not lines[0].strip():
_log_and_raise_error(logger, "No valid parameter line provided", ValueError)

# Set format to standard.
format_dict = FORMAT_STANDARD # NOTE: EXTENDED format is currently not supported.
# Set format to standard.
format_dict = FORMAT_STANDARD # NOTE: EXTENDED format is currently not supported.

main_line = f"{lines[0]:<80}" # Pad to full width

Expand All @@ -207,7 +208,7 @@ def from_lines(cls, lines: List[str], extended: bool = False) -> "IsotopeParamet

# Parse spin groups
spin_groups = []
group_format = SPIN_GROUP_STANDARD #NOTE: EXTENDED format is currently not supported.
group_format = SPIN_GROUP_STANDARD # NOTE: EXTENDED format is currently not supported.

# Helper function to parse groups from a line
def parse_groups(line: str, start_pos: int = None, continuation: bool = False) -> List[int]:
Expand Down Expand Up @@ -253,7 +254,7 @@ def parse_groups(line: str, start_pos: int = None, continuation: bool = False) -
spin_groups.extend(parse_groups(line, start_pos=0, continuation=True))

params["spin_groups"] = spin_groups

return cls(**params)

def to_lines(self, extended: bool = False) -> List[str]:
Expand Down Expand Up @@ -321,7 +322,7 @@ class IsotopeCard(BaseModel):
isotopes (List[IsotopeParameters]): List of isotope parameter sets
extended (bool): Whether to use extended format for >99 spin groups
NOTE: Fixed formats for both standard and extended are defined in the
NOTE: Fixed formats for both standard and extended are defined in the
IsotopeParameters class. But only using the standard format for now.
"""

Expand Down Expand Up @@ -378,12 +379,12 @@ def from_lines(cls, lines: List[str]) -> "IsotopeCard":
current_lines = []

for line in content_lines:

current_lines.append(line)

# check if characters 79-80 is a "-1". this means that there are more spin groups in the next line.
if line[78:80] == "-1": continue

if line[78:80] == "-1":
continue

# Otherwise the are no more lines for spin groups, so process the current lines.
else:
isotopes.append(IsotopeParameters.from_lines(current_lines, extended=extended))
Expand Down
2 changes: 1 addition & 1 deletion src/pleiades/sammy/parameters/notes/isotope_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
- to_lines

## Main Function
- Example usage
- Example usage
2 changes: 1 addition & 1 deletion src/pleiades/sammy/parameters/notes/radius_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@
- from_values

## Main Function
- Example usage
- Example usage
52 changes: 28 additions & 24 deletions src/pleiades/sammy/parameters/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
for radius parameters in SAMMY parameter files.
"""

import re, os
import os
import re
from enum import Enum
from typing import List, Optional, Tuple, Union

Expand All @@ -15,7 +16,7 @@
from pleiades.utils.logger import Logger, _log_and_raise_error

# Initialize logger with file logging
log_file_path = os.path.join(os.getcwd(), 'pleiades-par.log')
log_file_path = os.path.join(os.getcwd(), "pleiades-par.log")
logger = Logger(__name__, log_file=log_file_path)

####################################################################################################
Expand Down Expand Up @@ -47,6 +48,7 @@
# After IX=0 marker, channel numbers use 5 cols each
}


class RadiusFormat(Enum):
"""Supported formats for radius parameter cards."""

Expand Down Expand Up @@ -314,7 +316,7 @@ def _parse_spin_groups_and_channels(cls, line: str) -> Tuple[List[int], Optional
"""
where_am_i = "RadiusCardDefault._parse_spin_groups_and_channels()"
logger.info(f"{where_am_i}: Parsing spin groups and channels from line: {line}")

spin_groups = []
channels = None

Expand Down Expand Up @@ -416,7 +418,7 @@ def from_lines(cls, lines: List[str]) -> "RadiusCardDefault":
raise ValueError(f"Invalid parameter values: {e}")

logger.info(f"{where_am_i}: Successfully parsed radius parameters")

return cls(parameters=radius_parameters_list)

def to_lines(self) -> List[str]:
Expand All @@ -426,7 +428,7 @@ def to_lines(self) -> List[str]:
List[str]: Lines including header
"""
where_am_i = "RadiusCardDefault.to_lines()"

logger.info(f"{where_am_i}: Converting radius parameters to lines")
lines = []

Expand Down Expand Up @@ -928,16 +930,16 @@ def is_header_line(cls, line: str) -> bool:
"""
# set location for logger
where_am_i = "RadiusCard.is_header_line()"

line_upper = line.strip().upper()

logger.info(f"{where_am_i}: {line_upper}")

# Check all valid header formats
valid_headers = [
"RADIUS PARAMETERS FOLLOW", # Standard/Alternate fixed width
"RADII ARE IN KEY-WORD FORMAT", # Keyword format
"CHANNEL RADIUS PARAMETERS FOLLOW", # Alternative keyword format
"RADIUS PARAMETERS FOLLOW", # Standard/Alternate fixed width
"RADII ARE IN KEY-WORD FORMAT", # Keyword format
"CHANNEL RADIUS PARAMETERS FOLLOW", # Alternative keyword format
]

return any(header in line_upper for header in valid_headers)
Expand All @@ -959,17 +961,17 @@ def detect_format(cls, lines: List[str]) -> RadiusFormat:
if "KEY-WORD" in header:
logger.info(f"{where_am_i}: Detected keyword format!")
return RadiusFormat.KEYWORD

# If DEFAULT or ALTERNATE card formats then "RADIUS" should be in the header
elif "RADIU" in header:
# Check format by examining spin group columns
content_line = next((l for l in lines[1:] if l.strip()), "") # noqa: E741

# Check for alternate format (5-column integer values)
if len(content_line) >= 35 and content_line[25:30].strip(): # 5-col format
logger.info(f"{where_am_i}: Detected ALTERNATE format based on {content_line}")
return RadiusFormat.ALTERNATE

logger.info(f"{where_am_i}: Detected DEFAULT format based on {content_line}")
return RadiusFormat.DEFAULT

Expand All @@ -983,7 +985,7 @@ def from_lines(cls, lines: List[str]) -> "RadiusCard":
logger.info(f"{where_am_i}: Attempting to parse radius card from lines")
format_type = cls.detect_format(lines)

# Try reading in the radius card based on the determined format
# Try reading in the radius card based on the determined format
try:
if format_type == RadiusFormat.KEYWORD:
keyword_card = RadiusCardKeyword.from_lines(lines)
Expand All @@ -1003,7 +1005,7 @@ def from_lines(cls, lines: List[str]) -> "RadiusCard":
radius_card = cls(parameters=RadiusCardDefault.from_lines(lines).parameters)
logger.info(f"{where_am_i}: Successfully parsed radius card from lines in default format")
return radius_card

except Exception as e:
logger.error(f"{where_am_i}Failed to parse radius card: {str(e)}\nLines: {lines}")
raise ValueError(f"Failed to parse radius card: {str(e)}\nLines: {lines}")
Expand All @@ -1017,13 +1019,15 @@ def to_lines(self, radius_format: RadiusFormat = RadiusFormat.DEFAULT) -> List[s
if radius_format == RadiusFormat.KEYWORD:
lines = [CARD_7A_HEADER]
for param in self.parameters:
lines.extend(RadiusCardKeyword(
parameters=param,
particle_pair=self.particle_pair,
orbital_momentum=self.orbital_momentum,
relative_uncertainty=self.relative_uncertainty,
absolute_uncertainty=self.absolute_uncertainty,
).to_lines())
lines.extend(
RadiusCardKeyword(
parameters=param,
particle_pair=self.particle_pair,
orbital_momentum=self.orbital_momentum,
relative_uncertainty=self.relative_uncertainty,
absolute_uncertainty=self.absolute_uncertainty,
).to_lines()
)
elif radius_format == RadiusFormat.ALTERNATE:
lines = [CARD_7_ALT_HEADER]
for param in self.parameters:
Expand All @@ -1032,13 +1036,13 @@ def to_lines(self, radius_format: RadiusFormat = RadiusFormat.DEFAULT) -> List[s
lines = [CARD_7_HEADER]
for param in self.parameters:
lines.extend(RadiusCardDefault(parameters=[param]).to_lines())

# Add trailing blank line
lines.append("")

logger.info(f"{where_am_i}: Successfully wrote radius card")
return lines

except Exception as e:
logger.error(f"{where_am_i}: Failed to write radius card: {str(e)}")
raise ValueError(f"Failed to write radius card: {str(e)}")
Expand Down
14 changes: 7 additions & 7 deletions src/pleiades/sammy/parameters/resonance.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ class UnsupportedFormatError(ValueError):

class ResonanceEntry(BaseModel):
"""This class handles the parameters for a single resonance entry in Card Set 1 of a SAMMY parameter file.
Single resonance entry for SAMMY parameter file (strict format)
Attributes:
resonance_energy: Resonance energy Eλ (eV)
capture_width: Capture width Γγ (milli-eV)
channel1_width: Particle width for channel 1 (milli-eV)
channel2_width: Particle width for channel 2 (milli-eV)
channel3_width: Particle width for channel 3 (milli-eV)
NOTE: If any particle width Γ is negative, SAMMY uses abs(Γ)
NOTE: If any particle width Γ is negative, SAMMY uses abs(Γ)
for the width and set the associated amplitude γ to be negative.
vary_energy: Flag indicating if resonance energy is varied
vary_energy: Flag indicating if resonance energy is varied
vary_capture_width: Flag indicating if capture width is varied
vary_channel1: Flag indicating if channel 1 width is varied
vary_channel2: Flag indicating if channel 2 width is varied
vary_channel3: Flag indicating if channel 3 width is varied
NOTE: 0 = no, 1 = yes, 3 = PUP (PUP = Partially Unknown Parameter)
igroup: Quantum numbers group number (or spin_groups)
NOTE: If IGROUP is negative or greater than 50, this resonance will be
NOTE: If IGROUP is negative or greater than 50, this resonance will be
omitted from the calculation.
x_value: Special value used to detect multi-line entries (unsupported)
"""

resonance_energy: float = Field(description="Resonance energy Eλ (eV)")
Expand Down
Loading

0 comments on commit 2599a4f

Please sign in to comment.