- Convert System and Molecule classes to use @dataclass and field for defaults - Remove unused imports and legacy code from system.py - Move print_charges_and_dipole method from System to Player for better separation of concerns - Minor formatting and import order improvements for consistency
31 lines
915 B
Python
31 lines
915 B
Python
from diceplayer.environment.molecule import Molecule
|
|
|
|
from typing_extensions import List
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class System:
|
|
"""
|
|
System class declaration. This class is used throughout the DicePlayer program to represent the system containing the molecules.
|
|
|
|
Atributes:
|
|
molecule (List[Molecule]): List of molecules of the system
|
|
nmols (List[int]): List of number of molecules in the system
|
|
"""
|
|
|
|
nmols: List[int] = field(default_factory=list)
|
|
molecule: List[Molecule] = field(default_factory=list)
|
|
|
|
def add_type(self, m: Molecule) -> None:
|
|
"""
|
|
Adds a new molecule type to the system
|
|
|
|
Args:
|
|
m (Molecule): The instance of the new type of molecule
|
|
"""
|
|
if not isinstance(m, Molecule):
|
|
raise TypeError("Error: molecule is not a Molecule instance")
|
|
self.molecule.append(m)
|