feat: improves and initilize player pipeline

This commit is contained in:
2026-03-05 00:33:48 -03:00
parent 06ae9b41f0
commit 53eb34a83e
13 changed files with 248 additions and 60 deletions

View File

@@ -1,11 +1,12 @@
from pydantic import BaseModel, Field, ConfigDict
from typing_extensions import List, Literal
from pydantic import BaseModel, ConfigDict, Field
from typing_extensions import Literal
class DiceConfig(BaseModel):
"""
Data Transfer Object for the Dice configuration.
"""
model_config = ConfigDict(
frozen=True,
)
@@ -15,10 +16,10 @@ class DiceConfig(BaseModel):
..., description="Name of the output file for the simulation results"
)
dens: float = Field(..., description="Density of the system")
nmol: List[int] = Field(
nmol: list[int] = Field(
..., description="List of the number of molecules for each component"
)
nstep: List[int] = Field(
nstep: list[int] = Field(
...,
description="List of the number of steps for each component",
min_length=2,

View File

@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field, ConfigDict
from pydantic import BaseModel, ConfigDict, Field
from typing_extensions import Literal
@@ -6,14 +6,15 @@ class GaussianConfig(BaseModel):
"""
Data Transfer Object for the Gaussian configuration.
"""
model_config = ConfigDict(
frozen=True,
)
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"
)
level: str = Field(..., description="Level of theory for the QM calculations")
chgmult: list[int] = Field(
default_factory=lambda: [0, 1],
@@ -23,6 +24,6 @@ class GaussianConfig(BaseModel):
"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(
keywords: str | None = Field(
None, description="Additional keywords for the QM calculations"
)

View File

@@ -1,9 +1,10 @@
from diceplayer.config.dice_config import DiceConfig
from diceplayer.config.gaussian_config import GaussianConfig
from pydantic import BaseModel, Field, model_validator, ConfigDict
from typing_extensions import Self, Any
from pydantic import BaseModel, ConfigDict, Field, model_validator
from typing_extensions import Any
from enum import Enum
from pathlib import Path
@@ -11,18 +12,28 @@ MIN_STEP = 20000
STEP_INCREMENT = 1000
class RoutineType(str, Enum):
CHARGE = "charge"
GEOMETRY = "geometry"
BOTH = "both"
class PlayerConfig(BaseModel):
"""
Data Transfer Object for the player configuration.
"""
model_config = ConfigDict(
frozen=True,
)
opt: bool = Field(..., description="Whether to perform geometry optimization")
maxcyc: int = Field(
..., description="Maximum number of cycles for the geometry optimization"
type: RoutineType = Field(..., description="Type of simulation to perform")
max_cyc: int = Field(
..., description="Maximum number of cycles for the geometry optimization", gt=0
)
switch_cyc: int = Field(..., description="Switch cycle configuration")
mem: int = Field(None, description="Memory configuration")
nprocs: int = Field(
..., description="Number of processors to use for the QM calculations"
)
@@ -33,22 +44,37 @@ class PlayerConfig(BaseModel):
dice: DiceConfig = Field(..., description="Dice configuration")
gaussian: GaussianConfig = Field(..., description="Gaussian configuration")
mem: int = Field(None, description="Memory configuration")
switchcyc: int = Field(3, description="Switch cycle configuration")
qmprog: str = Field("g16", description="QM program to use for the calculations")
altsteps: int = Field(
20000, description="Number of steps for the alternate simulation"
)
geoms_file: Path = Field(
"geoms.xyz", description="File name for the geometries output"
Path("geoms.xyz"), description="File name for the geometries output"
)
simulation_dir: Path = Field(
"simfiles", description="Directory name for the simulation files"
Path("simfiles"), description="Directory name for the simulation files"
)
@model_validator(mode="before")
@staticmethod
def validate_altsteps(fields) -> dict[str, Any]:
altsteps = fields.pop("altsteps", MIN_STEP)
fields["altsteps"] = round(max(MIN_STEP, altsteps) / STEP_INCREMENT) * STEP_INCREMENT
fields["altsteps"] = (
round(max(MIN_STEP, altsteps) / STEP_INCREMENT) * STEP_INCREMENT
)
return fields
@model_validator(mode="before")
@staticmethod
def validate_switch_cyc(fields: dict[str, Any]) -> dict[str, Any]:
max_cyc = int(fields.get("max_cyc", 0))
switch_cyc = int(fields.get("switch_cyc", max_cyc))
if fields.get("type") == "both" and not switch_cyc < max_cyc:
raise ValueError("switch_cyc must be less than max_cyc when type='both'.")
if fields.get("type") != "both" and switch_cyc != max_cyc:
raise ValueError(
"switch_cyc must be equal to max_cyc when type is not 'both'."
)
return fields