Skip to content

Commit 961cc15

Browse files
author
pmblanco
committed
avoid regressions
1 parent cbe3eeb commit 961cc15

19 files changed

Lines changed: 121 additions & 198 deletions

‎pyMBE/storage/instances/bond.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#
1919

20+
from typing import Literal
2021
from pyMBE.storage.base_type import PMBBaseModel
2122
from pydantic import validator
2223

@@ -25,7 +26,7 @@ class BondInstance(PMBBaseModel):
2526
Instance representation of a bond between two particles.
2627
2728
Attributes:
28-
pmb_type ('str'):
29+
pmb_type ('Literal["bond"]'):
2930
Fixed identifier set to ``"bond"`` for all bond instances.
3031
3132
bond_id ('int'):
@@ -47,7 +48,7 @@ class BondInstance(PMBBaseModel):
4748
objects (e.g., Espresso bond handles). Those should be created
4849
by a runtime builder separate from the persistent database.
4950
"""
50-
pmb_type: str = "bond"
51+
pmb_type: Literal["bond"] = "bond"
5152
bond_id: int
5253
name : str # bond template name
5354
particle_id1: int

‎pyMBE/storage/instances/hydrogel.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#
1919

20+
from typing import Literal
2021
from ..base_type import PMBBaseModel
2122
from pydantic import validator
2223

@@ -25,7 +26,7 @@ class HydrogelInstance(PMBBaseModel):
2526
Persistent instance representation of a hydrogel object.
2627
2728
Attributes:
28-
pmb_type ('str'):
29+
pmb_type ('Literal["hydrogel"]'):
2930
Fixed string identifier for this instance type. Always ``"hydrogel"``.
3031
3132
assembly_id ('int'):
@@ -39,11 +40,11 @@ class HydrogelInstance(PMBBaseModel):
3940
hydrogel exists in the system), not a template describing generic
4041
hydrogel types.
4142
"""
42-
pmb_type: str = "hydrogel"
43+
pmb_type: Literal["hydrogel"] = "hydrogel"
4344
assembly_id: int
4445
name: str
4546
@validator("assembly_id")
46-
def validate_bond_id(cls, aid):
47+
def validate_assembly_id(cls, aid):
4748
if aid < 0:
4849
raise ValueError("assembly_id must be a non-negative integer.")
49-
return aid
50+
return aid

‎pyMBE/storage/instances/molecule.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
from pyMBE.storage.base_type import PMBBaseModel
2121
from pydantic import validator
22-
from typing import Optional
22+
from typing import Literal, Optional
2323

2424
class MoleculeInstance(PMBBaseModel):
2525
"""
2626
Persistent instance representation of a molecule.
2727
2828
Attributes:
29-
pmb_type ('str'):
29+
pmb_type ('Literal["molecule"]'):
3030
Fixed string identifying this object as a molecule instance. Always ``"molecule"``.
3131
3232
name ('str'):
@@ -35,15 +35,15 @@ class MoleculeInstance(PMBBaseModel):
3535
molecule_id ('int'):
3636
Unique non-negative integer identifying this molecule instance within the database.
3737
38-
assembly_id (int | None):
39-
Identifier of the super-parent assembly (e.g. hydrogel) to which this residue belongs. ``None`` indicates that the residue is not assigned to any assembly.
38+
assembly_id (Optional[int]):
39+
Identifier of the super-parent assembly (e.g. hydrogel) to which this molecule belongs. ``None`` indicates that the molecule is not assigned to any assembly.
4040
4141
Notes:
4242
- Validation of whether ``name`` corresponds to a registered molecule template is performed at the database level.
4343
- Structural or connectivity information (e.g., residue ordering) is maintained outside this class in the instance registry.
4444
"""
4545

46-
pmb_type: str = "molecule"
46+
pmb_type: Literal["molecule"] = "molecule"
4747
name: str # molecule template name
4848
molecule_id: int
4949
assembly_id: Optional[int] = None

‎pyMBE/storage/instances/particle.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#
1919

20-
from typing import Optional
20+
from typing import Literal, Optional
2121
from pydantic import validator
2222
from ..base_type import PMBBaseModel
2323

@@ -27,7 +27,7 @@ class ParticleInstance(PMBBaseModel):
2727
Concrete instance of a particle placed in the simulation.
2828
2929
Attributes:
30-
pmb_type ('str'):
30+
pmb_type ('Literal["particle"]'):
3131
Fixed string identifying this object as a particle instance. Always ``"particle"``.
3232
3333
name ('str'):
@@ -39,20 +39,20 @@ class ParticleInstance(PMBBaseModel):
3939
initial_state ('str'):
4040
Name of the particle state at creation time.
4141
42-
residue_id ('int' | 'None'):
42+
residue_id ('Optional[int]'):
4343
Optional identifier of the ``ResidueInstance`` this particle belongs to. Particles that are not part of a residue should leave this field as ``None``.
4444
45-
molecule_id ('int' | 'None'):
45+
molecule_id ('Optional[int]'):
4646
Optional identifier of the ``MoleculeInstance`` this particle belongs to. Particles not belonging to any molecule should keep this as ``None``.
4747
48-
assembly_id ('int' | 'None'):
48+
assembly_id ('Optional[int]'):
4949
Identifier of the super-parent assembly (e.g. hydrogel) to which this particle instance belongs. ``None`` indicates that the particle is not assigned to any assembly.
5050
5151
Notes:
5252
- ``initial_state`` is stored as a plain string to ensure clean serialization and avoid engine-specific objects.
5353
- Connectivity, bonding, and spatial ordering are external to this class and handled by the database or simulation backend.
5454
"""
55-
pmb_type: str = "particle"
55+
pmb_type: Literal["particle"] = "particle"
5656
name: str
5757
particle_id: int
5858
initial_state: str

‎pyMBE/storage/instances/peptide.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
from pyMBE.storage.base_type import PMBBaseModel
2121
from pydantic import validator
22-
from typing import Optional
22+
from typing import Literal, Optional
2323

2424

2525
class PeptideInstance(PMBBaseModel):
2626
"""
2727
Instance of a peptide molecule placed in the simulation.
2828
2929
Attributes:
30-
pmb_type ('str'):
30+
pmb_type ('Literal["peptide"]'):
3131
Fixed string identifying this object as a peptide instance. Always ``"peptide"``.
3232
3333
name ('str'):
@@ -36,14 +36,14 @@ class PeptideInstance(PMBBaseModel):
3636
molecule_id ('int'):
3737
Unique non-negative integer identifying this peptide within the database.
3838
39-
assembly_id ('int' | 'None'):
39+
assembly_id ('Optional[int]'):
4040
Identifier of the super-parent assembly (e.g. hydrogel) to which this residue belongs. ``None`` indicates that the residue is not assigned to any assembly.
4141
4242
Notes:
4343
- This class only tracks the identity of the peptide instance. Residues and particles belonging to the peptide reference this instance through their ``molecule_id`` fields.
4444
- Connectivity (ordering of residues), spatial arrangement, and bonding interactions are managed separately by the database or simulation engine.
4545
"""
46-
pmb_type: str = "peptide"
46+
pmb_type: Literal["peptide"] = "peptide"
4747
name: str # molecule template name
4848
molecule_id: int
4949
assembly_id: Optional[int] = None

‎pyMBE/storage/instances/protein.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
from pyMBE.storage.base_type import PMBBaseModel
2121
from pydantic import validator
22-
from typing import Optional
22+
from typing import Literal, Optional
2323

2424

2525
class ProteinInstance(PMBBaseModel):
2626
"""
2727
Instance of a protein molecule placed in the simulation.
2828
2929
Attributes:
30-
pmb_type ('str'):
30+
pmb_type ('Literal["protein"]'):
3131
Fixed string identifying this object as a protein instance. Always ``"protein"``.
3232
3333
name ('str'):
@@ -36,15 +36,15 @@ class ProteinInstance(PMBBaseModel):
3636
molecule_id ('int'):
3737
Unique non-negative integer identifying this protein within the database.
3838
39-
assembly_id ('int' | 'None'):
39+
assembly_id ('Optional[int]'):
4040
Identifier of the super-parent assembly (e.g. hydrogel) to which this residue belongs. ``None`` indicates that the residue is not assigned to any assembly.
4141
4242
Notes:
4343
- A ``ProteinInstance`` only records the identity of the protein and its template association.
4444
- Residues and particles that belong to the protein reference this instance through their ``molecule_id`` values.
4545
- The structural connectivity (residue sequence, domains) is handled at the template level or by the builder modules.
4646
"""
47-
pmb_type: str = "protein"
47+
pmb_type: Literal["protein"] = "protein"
4848
name: str # molecule template name
4949
molecule_id: int
5050
assembly_id: Optional[int] = None
@@ -53,4 +53,4 @@ class ProteinInstance(PMBBaseModel):
5353
def validate_residue_id(cls, mid):
5454
if mid < 0:
5555
raise ValueError("molecule_id must be a non-negative integer.")
56-
return mid
56+
return mid

‎pyMBE/storage/instances/residue.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
from pyMBE.storage.base_type import PMBBaseModel
2121
from pydantic import validator
22-
from typing import Optional
22+
from typing import Literal, Optional
2323

2424
class ResidueInstance(PMBBaseModel):
2525
"""
2626
Instance of a residue placed within a molecule during a simulation.
2727
2828
Attributes:
29-
pmb_type ('str'):
29+
pmb_type ('Literal["residue"]'):
3030
Fixed string identifying this object as a residue instance. Always ``"residue"``.
3131
3232
name ('str'):
@@ -35,18 +35,18 @@ class ResidueInstance(PMBBaseModel):
3535
residue_id ('int'):
3636
Unique non-negative integer identifying this residue instance within the database.
3737
38-
molecule_id ('int' | 'None'):
38+
molecule_id ('Optional[int]'):
3939
Identifier of the parent molecule to which this residue belongs. ``None`` indicates that the residue is not assigned to any molecule.
4040
41-
assembly_id ('int' | 'None'):
41+
assembly_id ('Optional[int]'):
4242
Identifier of the super-parent assembly (e.g. hydrogel) to which this residue belongs. ``None`` indicates that the residue is not assigned to any assembly.
4343
4444
Notes:
4545
- ``ResidueInstance`` does not itself store particle-level information; instead, particles reference the residue via ``residue_id``.
4646
- Residues may be standalone (e.g., in coarse systems) or part of polymers, proteins, peptides, or hydrogels.
4747
- The sequence ordering and topology of residues are encoded at the molecule instance/template level, not here.
4848
"""
49-
pmb_type: str = "residue"
49+
pmb_type: Literal["residue"] = "residue"
5050
name: str # residue template name
5151
residue_id: int
5252
molecule_id: Optional[int] = None

0 commit comments

Comments
 (0)