52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
from diceplayer.shared.utils.dataclass_protocol import Dataclass
|
|
|
|
from dataclasses import dataclass, fields
|
|
from typing import List
|
|
|
|
|
|
@dataclass
|
|
class DiceConfig(Dataclass):
|
|
"""
|
|
Data Transfer Object for the Dice configuration.
|
|
"""
|
|
|
|
ljname: str
|
|
outname: str
|
|
dens: float
|
|
nmol: List[int]
|
|
nstep: List[int]
|
|
|
|
upbuf = 360
|
|
combrule = "*"
|
|
isave: int = 1000
|
|
press: float = 1.0
|
|
temp: float = 300.0
|
|
progname: str = "dice"
|
|
randominit: str = "first"
|
|
|
|
def __post_init__(self):
|
|
if not isinstance(self.ljname, str):
|
|
raise ValueError("Error: 'ljname' keyword not specified in config file")
|
|
|
|
if not isinstance(self.outname, str):
|
|
raise ValueError("Error: 'outname' keyword not specified in config file")
|
|
|
|
if not isinstance(self.dens, float):
|
|
raise ValueError("Error: 'dens' keyword not specified in config file")
|
|
|
|
if not isinstance(self.nmol, list):
|
|
raise ValueError(
|
|
"Error: 'nmol' keyword not defined appropriately in config file"
|
|
)
|
|
|
|
if not isinstance(self.nstep, list) or len(self.nstep) not in (2, 3):
|
|
raise ValueError(
|
|
"Error: 'nstep' keyword not defined appropriately in config file"
|
|
)
|
|
|
|
@classmethod
|
|
def from_dict(cls, params: dict):
|
|
params = {f.name: params[f.name] for f in fields(cls) if f.name in params}
|
|
|
|
return cls(**params)
|