refactor: update dice handling and optimization flow to return structured results
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
import diceplayer.dice.dice_input as dice_input
|
||||
from diceplayer.config import DiceConfig
|
||||
from diceplayer.environment import System
|
||||
@@ -7,6 +9,10 @@ from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
|
||||
type DiceEnvironment = tuple[str, int, int, int]
|
||||
DiceEnvironmentAdapter = TypeAdapter(DiceEnvironment)
|
||||
|
||||
|
||||
DICE_FLAG_LINE: Final[int] = -2
|
||||
DICE_END_FLAG: Final[str] = "End of simulation"
|
||||
|
||||
@@ -35,9 +41,22 @@ class DiceWrapper:
|
||||
|
||||
raise RuntimeError(f"Dice simulation failed with exit status {exit_status}")
|
||||
|
||||
def parse_results(self, system: System) -> dict:
|
||||
results = {}
|
||||
def parse_results(self, system: System) -> list[DiceEnvironment]:
|
||||
NUMBER_OF_HEADER_LINES = 2
|
||||
NUMBER_OF_PRIMARY_ATOMS = len(system.molecule[0].atom)
|
||||
|
||||
results = []
|
||||
for output_file in sorted(self.working_directory.glob("phb*.xyz")):
|
||||
...
|
||||
with open(output_file, "r") as f:
|
||||
for _ in range(NUMBER_OF_HEADER_LINES + NUMBER_OF_PRIMARY_ATOMS):
|
||||
next(f, None)
|
||||
|
||||
for line in f:
|
||||
if line.strip() == "":
|
||||
break
|
||||
|
||||
results.append(
|
||||
DiceEnvironmentAdapter.validate_python(line.split())
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user