chore: fixes tests

This commit is contained in:
2026-02-26 06:23:30 -03:00
parent f56d6b6b36
commit e5c6282c86
18 changed files with 284 additions and 127 deletions

View File

View File

@@ -0,0 +1,27 @@
from pydantic import BaseModel, Field
from diceplayer.shared.utils.dataclass_protocol import Dataclass
from dataclasses import dataclass, fields
from typing import List, Literal
class DiceConfig(BaseModel):
"""
Data Transfer Object for the Dice configuration.
"""
ljname: str = Field(..., description="Name of the Lennard-Jones potential file")
outname: str = Field(..., description="Name of the output file for the simulation results")
dens: float = Field(..., description="Density of the system")
nmol: List[int] = Field(..., description="List of the number of molecules for each component")
nstep: List[int] = Field(..., description="List of the number of steps for each component", min_length=2, max_length=3)
upbuf: int = Field(360, description="Buffer size for the potential energy calculations")
combrule: Literal["+", "*"] = Field("*", description="Combination rule for the Lennard-Jones potential")
isave: int = Field(1000, description="Frequency of saving the simulation results")
press: float = Field(1.0, description="Pressure of the system")
temp: float = Field(300.0, description="Temperature of the system")
progname: str = Field("dice", description="Name of the program to run the simulation")
randominit: str = Field("first", description="Method for initializing the random number generator")
seed: int | None = Field(None, description="Seed for the random number generator")

View File

@@ -0,0 +1,21 @@
from typing import Literal
from pydantic import BaseModel, Field
from diceplayer.shared.utils.dataclass_protocol import Dataclass
from dataclasses import dataclass, fields
class GaussianConfig(BaseModel):
"""
Data Transfer Object for the Gaussian configuration.
"""
level: str = Field(..., description="Level of theory for the QM calculations")
qmprog: Literal["g03", "g09", "g16"] = Field("g16", description="QM program to use for the calculations")
chgmult: list[int] = Field(default_factory=lambda: [0, 1], description="List of charge and multiplicity for the QM calculations")
pop: str = Field("chelpg", description="Population analysis method for the QM calculations")
chg_tol: float = Field(0.01, description="Charge tolerance for the QM calculations")
keywords: str = Field(None, description="Additional keywords for the QM calculations")

View File

@@ -0,0 +1,46 @@
from diceplayer.config.dice_config import DiceConfig
from diceplayer.config.gaussian_config import GaussianConfig
from diceplayer.shared.utils.dataclass_protocol import Dataclass
from dataclasses import dataclass, fields
@dataclass
class PlayerConfig(Dataclass):
"""
Data Transfer Object for the player configuration.
"""
opt: bool
maxcyc: int
nprocs: int
ncores: int
dice: DiceConfig
gaussian: GaussianConfig
mem: int = None
switchcyc: int = 3
qmprog: str = "g16"
altsteps: int = 20000
geoms_file = "geoms.xyz"
simulation_dir = "simfiles"
def __post_init__(self):
MIN_STEP = 20000
# altsteps value is always the nearest multiple of 1000
self.altsteps = round(max(MIN_STEP, self.altsteps) / 1000) * 1000
@classmethod
def from_dict(cls, params: dict):
if params["dice"] is None:
raise ValueError("Error: 'dice' keyword not specified in config file.")
params["dice"] = DiceConfig.model_validate(params["dice"])
if params["gaussian"] is None:
raise ValueError("Error: 'gaussian' keyword not specified in config file.")
params["gaussian"] = GaussianConfig.model_validate(params["gaussian"])
params = {f.name: params[f.name] for f in fields(cls) if f.name in params}
return cls(**params)