@@ -114,11 +114,36 @@ def serialize(self, handler: SerializerFunctionWrapHandler, info: SerializationI
114114 return self_data
115115
116116
117- class SmallMolecule (FrozenWithAtoms ):
117+ class MolecularTypeMixin :
118+ molecular_type : MolecularType
119+
120+ def is_ion (self ) -> bool :
121+ return self .molecular_type == MolecularType .ION
122+
123+ def is_lipid (self ) -> bool :
124+ return self .molecular_type == MolecularType .LIPID
125+
126+ def is_solvent (self ) -> bool :
127+ return self .molecular_type == MolecularType .SOLVENT
128+
129+ def is_unknown (self ) -> bool :
130+ return self .molecular_type == MolecularType .UNKNOWN
131+
132+ def is_other (self ) -> bool :
133+ """Alias for MolecularTypeMixin.is_unknown()"""
134+ return self .is_unknown ()
135+
136+ def is_protein (self ) -> bool :
137+ return self .molecular_type == MolecularType .PROTEIN
138+
139+ def is_nucleic (self ) -> bool :
140+ return self .molecular_type == MolecularType .NUCLEIC
141+
142+
143+ class SmallMolecule (MolecularTypeMixin , FrozenWithAtoms ):
118144 """Small molecules are defined as residues with a single residue name."""
119145
120146 description : str
121- molecular_type : MolecularType
122147
123148 @computed_field
124149 @property
@@ -127,11 +152,9 @@ def name(self) -> str:
127152 return self .atoms .residues [0 ].resname
128153
129154
130- class Segment (FrozenWithAtoms ):
155+ class Segment (MolecularTypeMixin , FrozenWithAtoms ):
131156 """A segment is a group of atoms that are connected."""
132157
133- molecular_type : MolecularType # likely to be protein or nucleic acid
134-
135158 @computed_field
136159 @property
137160 def sequence (self ) -> str :
@@ -191,15 +214,13 @@ def check_number_of_atoms_is_valid(self):
191214 return self
192215
193216
194- class SmallMoleculeRead (BaseModelWithAtomsRead ):
217+ class SmallMoleculeRead (MolecularTypeMixin , BaseModelWithAtomsRead ):
195218 name : str
196219 description : str
197- molecular_type : MolecularType
198220
199221
200- class SegmentRead (BaseModelWithAtomsRead ):
222+ class SegmentRead (MolecularTypeMixin , BaseModelWithAtomsRead ):
201223 sequence : str
202- molecular_type : MolecularType
203224
204225
205226class InventoryRead (FrozenModel ):
0 commit comments