3535 from aiida .orm .querybuilder import FilterType , OrderByType , QueryBuilder
3636
3737__all__ = (
38- 'Collection' ,
3938 'Entity' ,
39+ 'EntityCollection' ,
40+ 'EntityModel' ,
4041 'EntityTypes' ,
41- 'Model' ,
4242)
4343
44- CollectionType = TypeVar ('CollectionType' , bound = 'Collection [Any]' )
45- EntityModelType = TypeVar ('EntityModelType' , bound = 'Model ' )
44+ CollectionType = TypeVar ('CollectionType' , bound = 'EntityCollection [Any]' )
45+ EntityModelType = TypeVar ('EntityModelType' , bound = 'EntityModel ' )
4646EntityType = TypeVar ('EntityType' , bound = 'Entity[Any,Any,Any]' )
4747BackendEntityType = TypeVar ('BackendEntityType' , bound = 'BackendEntity' )
4848
@@ -61,7 +61,7 @@ class EntityTypes(Enum):
6161 GROUP_NODE = 'group_node'
6262
6363
64- class Collection (abc .ABC , Generic [EntityType ]):
64+ class EntityCollection (abc .ABC , Generic [EntityType ]):
6565 """Container class that represents the collection of objects of a particular entity type."""
6666
6767 @staticmethod
@@ -184,7 +184,7 @@ def count(self, filters: Optional['FilterType'] = None) -> int:
184184 return self .query (filters = filters ).count ()
185185
186186
187- class Model (BaseModel , defer_build = True ):
187+ class EntityModel (BaseModel , defer_build = True ):
188188 model_config = ConfigDict (extra = 'forbid' )
189189
190190 pk : int = MetadataField (
@@ -194,16 +194,6 @@ class Model(BaseModel, defer_build=True):
194194 exclude_from_cli = True ,
195195 )
196196
197- @classmethod
198- def __pydantic_init_subclass__ (cls , ** kwargs : Any ) -> None :
199- """Sets the JSON schema title of the model.
200-
201- The qualified name of the class is used, with dots removed. For example, `Node.Model` becomes `NodeModel`
202- in the JSON schema.
203- """
204- super ().__pydantic_init_subclass__ (** kwargs )
205- cls .model_config ['title' ] = cls .__qualname__ .replace ('.' , '' )
206-
207197 @classmethod
208198 def as_input_model (cls : Type [EntityModelType ]) -> Type [EntityModelType ]:
209199 """Return a derived model class with read-only fields removed.
@@ -214,7 +204,7 @@ def as_input_model(cls: Type[EntityModelType]) -> Type[EntityModelType]:
214204 """
215205
216206 # Derive the input model from the original model
217- new_name = cls .__qualname__ .replace ('. Model' , 'InputModel' )
207+ new_name = cls .__qualname__ .replace ('Model' , 'InputModel' )
218208 InputModel = create_model ( # noqa: N806
219209 new_name ,
220210 __base__ = cls ,
@@ -257,10 +247,18 @@ def _prune_field_decorators(field_decorators: dict[str, Any]) -> dict[str, Any]:
257247class Entity (abc .ABC , Generic [BackendEntityType , CollectionType , EntityModelType ], metaclass = EntityFieldMeta ):
258248 """An AiiDA entity"""
259249
260- _CLS_COLLECTION : type [CollectionType ] = Collection # type: ignore[assignment]
261- _CLS_MODEL : type [EntityModelType ] = Model # type: ignore[assignment]
250+ _CLS_COLLECTION : type [CollectionType ] = EntityCollection # type: ignore[assignment]
251+ _CLS_MODEL : type [EntityModelType ] = EntityModel # type: ignore[assignment]
262252 _logger = log .AIIDA_LOGGER .getChild ('orm.entities' )
263253
254+ @classproperty
255+ def Model (cls ) -> Type [EntityModelType ]: # noqa: N802, N805
256+ """Return the model class for this entity.
257+
258+ :return: The model class.
259+ """
260+ return cls ._CLS_MODEL
261+
264262 @classproperty
265263 def InputModel (cls ) -> Type [EntityModelType ]: # noqa: N802, N805
266264 """Return the input version of the model class for this entity.
@@ -272,9 +270,7 @@ def InputModel(cls) -> Type[EntityModelType]: # noqa: N802, N805
272270 @classmethod
273271 def model_to_orm_fields (cls ) -> dict [str , FieldInfo ]:
274272 return {
275- key : field
276- for key , field in cls ._CLS_MODEL .model_fields .items ()
277- if not get_metadata (field , 'exclude_to_orm' )
273+ key : field for key , field in cls .Model .model_fields .items () if not get_metadata (field , 'exclude_to_orm' )
278274 }
279275
280276 @classmethod
@@ -325,7 +321,7 @@ def to_model(
325321 with `exclude_to_orm=True`.
326322 :return: An instance of the entity's model class.
327323 """
328- Model = self .InputModel if unstored else self ._CLS_MODEL # noqa: N806
324+ Model = self .InputModel if unstored else self .Model # noqa: N806
329325 fields = self ._collect_model_field_values (
330326 repository_path = repository_path ,
331327 serialize_repository_content = serialize_repository_content ,
@@ -396,7 +392,7 @@ def from_serialized(cls, serialized: dict[str, Any], unstored: bool = False) ->
396392 cls ._logger .warning (
397393 'Serialization through pydantic is still an experimental feature and might break in future releases.'
398394 )
399- Model = cls .InputModel if unstored else cls ._CLS_MODEL # noqa: N806
395+ Model = cls .InputModel if unstored else cls .Model # noqa: N806
400396 return cls .from_model (Model (** serialized ))
401397
402398 @classproperty
@@ -542,7 +538,7 @@ def _collect_model_field_values(
542538 """
543539 fields : dict [str , Any ] = {}
544540
545- Model = self .InputModel if unstored else self ._CLS_MODEL # noqa: N806
541+ Model = self .InputModel if unstored else self .Model # noqa: N806
546542
547543 for key , field in Model .model_fields .items ():
548544 if skip_cli_excluded and get_metadata (field , 'exclude_from_cli' ):
0 commit comments