diff --git a/notebooks/metadata_schema.ipynb b/notebooks/metadata_schema.ipynb index 6bbe994..9f55c23 100644 --- a/notebooks/metadata_schema.ipynb +++ b/notebooks/metadata_schema.ipynb @@ -2,196 +2,43 @@ "cells": [ { "cell_type": "code", - "execution_count": 8, + "execution_count": 1, "id": "9058253b-d5f3-4e70-8952-61f7d2992b08", "metadata": {}, - "outputs": [], - "source": [ - "from pyscal_rdf.network.ontology import read_ontology\n", - "from rdflib import Graph, Literal, Namespace\n", - "import copy" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "4c5d73b6-da02-420c-a223-4eef93c872bc", - "metadata": {}, - "outputs": [], - "source": [ - "onto = read_ontology()" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "09f55784-36b9-471d-a766-4a3a017f7696", - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'cmso:hasAltName': cmso:hasAltName,\n", - " 'cmso:hasName': cmso:hasName,\n", - " 'cmso:hasAngle_alpha': cmso:hasAngle_alpha,\n", - " 'cmso:hasAngle_beta': cmso:hasAngle_beta,\n", - " 'cmso:hasAngle_gamma': cmso:hasAngle_gamma,\n", - " 'cmso:hasChemicalSymbol': cmso:hasChemicalSymbol,\n", - " 'cmso:hasSymbol': cmso:hasSymbol,\n", - " 'cmso:hasComponent_x': cmso:hasComponent_x,\n", - " 'cmso:hasComponent_y': cmso:hasComponent_y,\n", - " 'cmso:hasComponent_z': cmso:hasComponent_z,\n", - " 'cmso:hasCoordinationNumber': cmso:hasCoordinationNumber,\n", - " 'cmso:hasElementRatio': cmso:hasElementRatio,\n", - " 'cmso:hasLength_x': cmso:hasLength_x,\n", - " 'cmso:hasLength_y': cmso:hasLength_y,\n", - " 'cmso:hasLength_z': cmso:hasLength_z,\n", - " 'cmso:hasNumberOfAtoms': cmso:hasNumberOfAtoms,\n", - " 'cmso:hasReference': cmso:hasReference,\n", - " 'cmso:hasRepetition_x': cmso:hasRepetition_x,\n", - " 'cmso:hasRepetition_y': cmso:hasRepetition_y,\n", - " 'cmso:hasRepetition_z': cmso:hasRepetition_z,\n", - " 'cmso:hasSpaceGroupNumber': cmso:hasSpaceGroupNumber,\n", - " 'cmso:hasSpaceGroupSymbol': cmso:hasSpaceGroupSymbol,\n", - " 'cmso:hasValue': cmso:hasValue,\n", - " 'cmso:hasVolume': cmso:hasVolume,\n", - " 'pldo:geometricalDegreesOfFreedom': pldo:geometricalDegreesOfFreedom,\n", - " 'pldo:hasGBplane': pldo:hasGBplane,\n", - " 'pldo:macroscopicDegreesOfFreedom': pldo:macroscopicDegreesOfFreedom,\n", - " 'pldo:hasMisorientationAngle': pldo:hasMisorientationAngle,\n", - " 'pldo:hasRotationAxis': pldo:hasRotationAxis,\n", - " 'pldo:hasSigmaValue': pldo:hasSigmaValue,\n", - " 'pldo:microscopicDegreesOfFreedom': pldo:microscopicDegreesOfFreedom,\n", - " 'podo:hasNumberOfVacancies': podo:hasNumberOfVacancies,\n", - " 'podo:hasVacancyConcentration': podo:hasVacancyConcentration,\n", - " 'rdfs:label': rdfs:label}" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "onto.attributes['data_property']" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "ce296bb0-8e6a-4ab2-8940-52d6a0121e6f", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "['cmso:SimulationCell']" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "onto.attributes['data_property']['cmso:hasVolume'].domain" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "8dc0e696-b128-4ebe-9ebe-3312e8b04124", - "metadata": {}, - "outputs": [], - "source": [ - "def create_dict(datadict, path):\n", - " for p in path:\n", - " datadict[str(p[0])] ={}\n", - " datadict = datadict[str(p[0])]\n", - " #exists\n", - " datadict[str(p[0])] = {str(p[-1]): None}" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "7d267c94-b4f2-4fe8-be2e-c44f4300c128", - "metadata": {}, - "outputs": [], - "source": [ - "collected_dicts = []" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "c87873b0-62d1-40d1-a6f3-9418e0f8c8d2", - "metadata": {}, - "outputs": [], - "source": [ - "for key in onto.attributes['data_property']:\n", - " try:\n", - " path = onto.get_path_from_sample(key)\n", - " datadict = {}\n", - " create_dict(datadict, path)\n", - " collected_dicts.append(copy.deepcopy(datadict))\n", - " except:\n", - " pass" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "30d5eae4-d4a4-432d-99cc-7ec8e5944225", - "metadata": {}, - "outputs": [], - "source": [ - "def dict_merge(dct, merge_dct):\n", - " for k, v in merge_dct.items():\n", - " if (k in dct and isinstance(dct[k], dict) and isinstance(merge_dct[k], dict)): #noqa\n", - " dict_merge(dct[k], merge_dct[k])\n", - " else:\n", - " dct[k] = merge_dct[k]\n", - " \n", - " \n", - "collected_dicts = []\n", - "\n", - "for key in o.attributes['data_node']:\n", - " try:\n", - " path = o.get_path_from_sample(key)\n", - " datadict = {}\n", - " create_dict(datadict, path)\n", - " collected_dicts.append(copy.deepcopy(datadict))\n", - " except:\n", - " pass" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "f407cffc-c1ba-4d51-ae78-0c580a77dea1", - "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'cmso:ComputationalSample': {'cmso:SimulationCell': {'cmso:Angle': {'cmso:Angle': {'cmso:hasAngle_gamma': None}}}}}" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" + "ename": "PydanticSchemaGenerationError", + "evalue": "Unable to generate pydantic-core schema for []. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.\n\nIf you got this error by calling handler() within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema()` since we do not call `__get_pydantic_core_schema__` on `` otherwise to avoid infinite recursion.\n\nFor further information visit https://errors.pydantic.dev/2.4/u/schema-for-unknown-type", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mPydanticSchemaGenerationError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyscal_rdf\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mschema\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Sample\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pyscal_rdf/schema.py:63\u001b[0m\n\u001b[1;32m 60\u001b[0m \tcrystal_structure: Optional[CrystalStructure] \u001b[38;5;241m=\u001b[39m CrystalStructure()\n\u001b[1;32m 61\u001b[0m \tdefect: Optional[Defect] \u001b[38;5;241m=\u001b[39m Defect()\n\u001b[0;32m---> 63\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mSample\u001b[39;00m(BaseModel, title\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSample\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 64\u001b[0m \t\u001b[38;5;66;03m#material: Optional[Material] = Material()\u001b[39;00m\n\u001b[1;32m 65\u001b[0m \t\u001b[38;5;66;03m#simulation_cell: Optional[SimulationCell] = SimulationCell()\u001b[39;00m\n\u001b[1;32m 66\u001b[0m \tcalculated_property: [CalculatedProperty] \u001b[38;5;241m=\u001b[39m CalculatedProperty()\n\u001b[1;32m 67\u001b[0m \t\u001b[38;5;66;03m#pass\u001b[39;00m\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py:184\u001b[0m, in \u001b[0;36mModelMetaclass.__new__\u001b[0;34m(mcs, cls_name, bases, namespace, __pydantic_generic_metadata__, __pydantic_reset_parent_namespace__, **kwargs)\u001b[0m\n\u001b[1;32m 182\u001b[0m types_namespace \u001b[38;5;241m=\u001b[39m get_cls_types_namespace(\u001b[38;5;28mcls\u001b[39m, parent_namespace)\n\u001b[1;32m 183\u001b[0m set_model_fields(\u001b[38;5;28mcls\u001b[39m, bases, config_wrapper, types_namespace)\n\u001b[0;32m--> 184\u001b[0m \u001b[43mcomplete_model_class\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 185\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 186\u001b[0m \u001b[43m \u001b[49m\u001b[43mcls_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 187\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig_wrapper\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 188\u001b[0m \u001b[43m \u001b[49m\u001b[43mraise_errors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 189\u001b[0m \u001b[43m \u001b[49m\u001b[43mtypes_namespace\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtypes_namespace\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 190\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 191\u001b[0m \u001b[38;5;66;03m# using super(cls, cls) on the next line ensures we only call the parent class's __pydantic_init_subclass__\u001b[39;00m\n\u001b[1;32m 192\u001b[0m \u001b[38;5;66;03m# I believe the `type: ignore` is only necessary because mypy doesn't realize that this code branch is\u001b[39;00m\n\u001b[1;32m 193\u001b[0m \u001b[38;5;66;03m# only hit for _proper_ subclasses of BaseModel\u001b[39;00m\n\u001b[1;32m 194\u001b[0m \u001b[38;5;28msuper\u001b[39m(\u001b[38;5;28mcls\u001b[39m, \u001b[38;5;28mcls\u001b[39m)\u001b[38;5;241m.\u001b[39m__pydantic_init_subclass__(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py:481\u001b[0m, in \u001b[0;36mcomplete_model_class\u001b[0;34m(cls, cls_name, config_wrapper, raise_errors, types_namespace)\u001b[0m\n\u001b[1;32m 478\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 481\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__get_pydantic_core_schema__\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mhandler\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 482\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m PydanticUndefinedAnnotation \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 483\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m raise_errors:\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/main.py:576\u001b[0m, in \u001b[0;36mBaseModel.__get_pydantic_core_schema__\u001b[0;34m(cls, _BaseModel__source, _BaseModel__handler)\u001b[0m\n\u001b[1;32m 573\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m__pydantic_generic_metadata__[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124morigin\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[1;32m 574\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m__pydantic_core_schema__\n\u001b[0;32m--> 576\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m__handler\u001b[49m\u001b[43m(\u001b[49m\u001b[43m__source\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py:82\u001b[0m, in \u001b[0;36mCallbackGetCoreSchemaHandler.__call__\u001b[0;34m(self, _CallbackGetCoreSchemaHandler__source_type)\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, __source_type: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mCoreSchema:\n\u001b[0;32m---> 82\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_handler\u001b[49m\u001b[43m(\u001b[49m\u001b[43m__source_type\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 83\u001b[0m ref \u001b[38;5;241m=\u001b[39m schema\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mref\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_ref_mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mto-def\u001b[39m\u001b[38;5;124m'\u001b[39m:\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:452\u001b[0m, in \u001b[0;36mGenerateSchema.generate_schema\u001b[0;34m(self, obj, from_dunder_get_core_schema)\u001b[0m\n\u001b[1;32m 449\u001b[0m schema \u001b[38;5;241m=\u001b[39m from_property\n\u001b[1;32m 451\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m schema \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 452\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 454\u001b[0m metadata_js_function \u001b[38;5;241m=\u001b[39m _extract_get_pydantic_json_schema(obj, schema)\n\u001b[1;32m 455\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m metadata_js_function \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:684\u001b[0m, in \u001b[0;36mGenerateSchema._generate_schema\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 682\u001b[0m needs_apply_discriminated_union \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union\n\u001b[1;32m 683\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m--> 684\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_post_process_generated_schema(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_schema_inner\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 685\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_has_invalid_schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_has_invalid_schema \u001b[38;5;129;01mor\u001b[39;00m has_invalid_schema\n\u001b[1;32m 686\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union \u001b[38;5;129;01mor\u001b[39;00m needs_apply_discriminated_union\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:706\u001b[0m, in \u001b[0;36mGenerateSchema._generate_schema_inner\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 703\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmain\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BaseModel\n\u001b[1;32m 705\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m lenient_issubclass(obj, BaseModel):\n\u001b[0;32m--> 706\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_model_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 708\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(obj, PydanticRecursiveRef):\n\u001b[1;32m 709\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m core_schema\u001b[38;5;241m.\u001b[39mdefinition_reference_schema(schema_ref\u001b[38;5;241m=\u001b[39mobj\u001b[38;5;241m.\u001b[39mtype_ref)\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:525\u001b[0m, in \u001b[0;36mGenerateSchema._model_schema\u001b[0;34m(self, cls)\u001b[0m\n\u001b[1;32m 513\u001b[0m model_schema \u001b[38;5;241m=\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mmodel_schema(\n\u001b[1;32m 514\u001b[0m \u001b[38;5;28mcls\u001b[39m,\n\u001b[1;32m 515\u001b[0m inner_schema,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 521\u001b[0m metadata\u001b[38;5;241m=\u001b[39mmetadata,\n\u001b[1;32m 522\u001b[0m )\n\u001b[1;32m 523\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 524\u001b[0m fields_schema: core_schema\u001b[38;5;241m.\u001b[39mCoreSchema \u001b[38;5;241m=\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mmodel_fields_schema(\n\u001b[0;32m--> 525\u001b[0m {k: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate_md_field_schema(k, v, decorators) \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m fields\u001b[38;5;241m.\u001b[39mitems()},\n\u001b[1;32m 526\u001b[0m computed_fields\u001b[38;5;241m=\u001b[39m[\n\u001b[1;32m 527\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_computed_field_schema(d, decorators\u001b[38;5;241m.\u001b[39mfield_serializers)\n\u001b[1;32m 528\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m d \u001b[38;5;129;01min\u001b[39;00m computed_fields\u001b[38;5;241m.\u001b[39mvalues()\n\u001b[1;32m 529\u001b[0m ],\n\u001b[1;32m 530\u001b[0m extras_schema\u001b[38;5;241m=\u001b[39mextras_schema,\n\u001b[1;32m 531\u001b[0m model_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m,\n\u001b[1;32m 532\u001b[0m )\n\u001b[1;32m 533\u001b[0m inner_schema \u001b[38;5;241m=\u001b[39m apply_validators(fields_schema, decorators\u001b[38;5;241m.\u001b[39mroot_validators\u001b[38;5;241m.\u001b[39mvalues(), \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m 534\u001b[0m new_inner_schema \u001b[38;5;241m=\u001b[39m define_expected_missing_refs(inner_schema, recursively_defined_type_refs())\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:525\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 513\u001b[0m model_schema \u001b[38;5;241m=\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mmodel_schema(\n\u001b[1;32m 514\u001b[0m \u001b[38;5;28mcls\u001b[39m,\n\u001b[1;32m 515\u001b[0m inner_schema,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 521\u001b[0m metadata\u001b[38;5;241m=\u001b[39mmetadata,\n\u001b[1;32m 522\u001b[0m )\n\u001b[1;32m 523\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 524\u001b[0m fields_schema: core_schema\u001b[38;5;241m.\u001b[39mCoreSchema \u001b[38;5;241m=\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mmodel_fields_schema(\n\u001b[0;32m--> 525\u001b[0m {k: \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_md_field_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdecorators\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m fields\u001b[38;5;241m.\u001b[39mitems()},\n\u001b[1;32m 526\u001b[0m computed_fields\u001b[38;5;241m=\u001b[39m[\n\u001b[1;32m 527\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_computed_field_schema(d, decorators\u001b[38;5;241m.\u001b[39mfield_serializers)\n\u001b[1;32m 528\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m d \u001b[38;5;129;01min\u001b[39;00m computed_fields\u001b[38;5;241m.\u001b[39mvalues()\n\u001b[1;32m 529\u001b[0m ],\n\u001b[1;32m 530\u001b[0m extras_schema\u001b[38;5;241m=\u001b[39mextras_schema,\n\u001b[1;32m 531\u001b[0m model_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m,\n\u001b[1;32m 532\u001b[0m )\n\u001b[1;32m 533\u001b[0m inner_schema \u001b[38;5;241m=\u001b[39m apply_validators(fields_schema, decorators\u001b[38;5;241m.\u001b[39mroot_validators\u001b[38;5;241m.\u001b[39mvalues(), \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m 534\u001b[0m new_inner_schema \u001b[38;5;241m=\u001b[39m define_expected_missing_refs(inner_schema, recursively_defined_type_refs())\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:870\u001b[0m, in \u001b[0;36mGenerateSchema._generate_md_field_schema\u001b[0;34m(self, name, field_info, decorators)\u001b[0m\n\u001b[1;32m 863\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_md_field_schema\u001b[39m(\n\u001b[1;32m 864\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 865\u001b[0m name: \u001b[38;5;28mstr\u001b[39m,\n\u001b[1;32m 866\u001b[0m field_info: FieldInfo,\n\u001b[1;32m 867\u001b[0m decorators: DecoratorInfos,\n\u001b[1;32m 868\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mModelField:\n\u001b[1;32m 869\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Prepare a ModelField to represent a model field.\"\"\"\u001b[39;00m\n\u001b[0;32m--> 870\u001b[0m common_field \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_common_field_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfield_info\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdecorators\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 871\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m core_schema\u001b[38;5;241m.\u001b[39mmodel_field(\n\u001b[1;32m 872\u001b[0m common_field[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mschema\u001b[39m\u001b[38;5;124m'\u001b[39m],\n\u001b[1;32m 873\u001b[0m serialization_exclude\u001b[38;5;241m=\u001b[39mcommon_field[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mserialization_exclude\u001b[39m\u001b[38;5;124m'\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 877\u001b[0m metadata\u001b[38;5;241m=\u001b[39mcommon_field[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m'\u001b[39m],\n\u001b[1;32m 878\u001b[0m )\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:923\u001b[0m, in \u001b[0;36mGenerateSchema._common_field_schema\u001b[0;34m(self, name, field_info, decorators)\u001b[0m\n\u001b[1;32m 921\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_apply_annotations(source_type, annotations, transform_inner_schema\u001b[38;5;241m=\u001b[39mset_discriminator)\n\u001b[1;32m 922\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 923\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_apply_annotations\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 924\u001b[0m \u001b[43m \u001b[49m\u001b[43msource_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 925\u001b[0m \u001b[43m \u001b[49m\u001b[43mannotations\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 926\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 928\u001b[0m \u001b[38;5;66;03m# This V1 compatibility shim should eventually be removed\u001b[39;00m\n\u001b[1;32m 929\u001b[0m \u001b[38;5;66;03m# push down any `each_item=True` validators\u001b[39;00m\n\u001b[1;32m 930\u001b[0m \u001b[38;5;66;03m# note that this won't work for any Annotated types that get wrapped by a function validator\u001b[39;00m\n\u001b[1;32m 931\u001b[0m \u001b[38;5;66;03m# but that's okay because that didn't exist in V1\u001b[39;00m\n\u001b[1;32m 932\u001b[0m this_field_validators \u001b[38;5;241m=\u001b[39m filter_field_decorator_info_by_field(decorators\u001b[38;5;241m.\u001b[39mvalidators\u001b[38;5;241m.\u001b[39mvalues(), name)\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:1592\u001b[0m, in \u001b[0;36mGenerateSchema._apply_annotations\u001b[0;34m(self, source_type, annotations, transform_inner_schema)\u001b[0m\n\u001b[1;32m 1587\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m 1588\u001b[0m get_inner_schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_wrapped_inner_schema(\n\u001b[1;32m 1589\u001b[0m get_inner_schema, annotation, pydantic_js_annotation_functions\n\u001b[1;32m 1590\u001b[0m )\n\u001b[0;32m-> 1592\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[43mget_inner_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43msource_type\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1593\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m pydantic_js_annotation_functions:\n\u001b[1;32m 1594\u001b[0m metadata \u001b[38;5;241m=\u001b[39m CoreMetadataHandler(schema)\u001b[38;5;241m.\u001b[39mmetadata\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py:82\u001b[0m, in \u001b[0;36mCallbackGetCoreSchemaHandler.__call__\u001b[0;34m(self, _CallbackGetCoreSchemaHandler__source_type)\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, __source_type: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m core_schema\u001b[38;5;241m.\u001b[39mCoreSchema:\n\u001b[0;32m---> 82\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_handler\u001b[49m\u001b[43m(\u001b[49m\u001b[43m__source_type\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 83\u001b[0m ref \u001b[38;5;241m=\u001b[39m schema\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mref\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_ref_mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mto-def\u001b[39m\u001b[38;5;124m'\u001b[39m:\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:1573\u001b[0m, in \u001b[0;36mGenerateSchema._apply_annotations..inner_handler\u001b[0;34m(obj)\u001b[0m\n\u001b[1;32m 1571\u001b[0m from_property \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate_schema_from_property(obj, obj)\n\u001b[1;32m 1572\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m from_property \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 1573\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1574\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1575\u001b[0m schema \u001b[38;5;241m=\u001b[39m from_property\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:684\u001b[0m, in \u001b[0;36mGenerateSchema._generate_schema\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 682\u001b[0m needs_apply_discriminated_union \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union\n\u001b[1;32m 683\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m--> 684\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_post_process_generated_schema(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_schema_inner\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 685\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_has_invalid_schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_has_invalid_schema \u001b[38;5;129;01mor\u001b[39;00m has_invalid_schema\n\u001b[1;32m 686\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_needs_apply_discriminated_union \u001b[38;5;129;01mor\u001b[39;00m needs_apply_discriminated_union\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:711\u001b[0m, in \u001b[0;36mGenerateSchema._generate_schema_inner\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 708\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(obj, PydanticRecursiveRef):\n\u001b[1;32m 709\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m core_schema\u001b[38;5;241m.\u001b[39mdefinition_reference_schema(schema_ref\u001b[38;5;241m=\u001b[39mobj\u001b[38;5;241m.\u001b[39mtype_ref)\n\u001b[0;32m--> 711\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmatch_type\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:798\u001b[0m, in \u001b[0;36mGenerateSchema.match_type\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 796\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_arbitrary_types:\n\u001b[1;32m 797\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_arbitrary_type_schema(obj)\n\u001b[0;32m--> 798\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_unknown_type_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/miniconda3/envs/rdf-wf-6/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:366\u001b[0m, in \u001b[0;36mGenerateSchema._unknown_type_schema\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 365\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_unknown_type_schema\u001b[39m(\u001b[38;5;28mself\u001b[39m, obj: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m CoreSchema:\n\u001b[0;32m--> 366\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m PydanticSchemaGenerationError(\n\u001b[1;32m 367\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUnable to generate pydantic-core schema for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mobj\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 368\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSet `arbitrary_types_allowed=True` in the model_config to ignore this error\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 369\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m or implement `__get_pydantic_core_schema__` on your type to fully support it.\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 370\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mIf you got this error by calling handler() within\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 371\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m `__get_pydantic_core_schema__` then you likely need to call\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 372\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m `handler.generate_schema()` since we do not call\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 373\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m `__get_pydantic_core_schema__` on `` otherwise to avoid infinite recursion.\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 374\u001b[0m )\n", + "\u001b[0;31mPydanticSchemaGenerationError\u001b[0m: Unable to generate pydantic-core schema for []. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.\n\nIf you got this error by calling handler() within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema()` since we do not call `__get_pydantic_core_schema__` on `` otherwise to avoid infinite recursion.\n\nFor further information visit https://errors.pydantic.dev/2.4/u/schema-for-unknown-type" + ] } ], "source": [ - "collected_dicts[3]" + "from pyscal_rdf.schema import Sample" ] }, { diff --git a/pyscal_rdf/schema.py b/pyscal_rdf/schema.py index f9d3c1e..740221c 100644 --- a/pyscal_rdf/schema.py +++ b/pyscal_rdf/schema.py @@ -25,17 +25,17 @@ class CalculatedProperty(BaseModel, title='calculated property'): class SimulationCell(BaseModel, title='Simulation cell'): volume: Annotated[float, Field(default=0, ge=0)] number_of_atoms: Annotated[int, Field(default=0, ge=0)] - length: Annotated[conlist(float, min_length=3, max_length=3), Field(default=0, ge=0)] + length: Annotated[conlist(float, min_length=3, max_length=3), Field(default=[0,0,0])] vector: Annotated[conlist(conlist(float, min_length=3, max_length=3), - min_length=3, max_length=3), Field(default=0)] - angle: Annotated[conlist(float, min_length=3, max_length=3), Field(default=0, ge=0)] + min_length=3, max_length=3), Field(default=None)] + angle: Annotated[conlist(float, min_length=3, max_length=3), Field(default=[0,0,0])] vacancy_concentration: Annotated[float, Field(default=0, ge=0)] number_of_vacancies: Annotated[int, Field(default=0, ge=0)] class UnitCell(BaseModel, title='Unit cell'): bravais_lattice: Annotated[str, Field(default=None, required=False)] lattice_parameter: Annotated[Union[float, conlist(float, min_length=3, max_length=3)], - Field(default=0), required=False] + Field(default=0, required=False)] angle: Annotated[conlist(float, min_length=3, max_length=3), Field(default=[90.0, 90.0, 90.0], required=False)] @@ -56,15 +56,15 @@ class Defect(BaseModel, title='General defect class'): grain_boundary: Optional[GrainBoundary] = GrainBoundary() class Material(BaseModel, title='Material'): - element_ratio: Annotated[dict] + element_ratio: Annotated[dict, Field(default={})] crystal_structure: Optional[CrystalStructure] = CrystalStructure() defect: Optional[Defect] = Defect() - + class Sample(BaseModel, title='Sample'): material: Optional[Material] = Material() simulation_cell: Optional[SimulationCell] = SimulationCell() - calculated_property[CalculatedProperty] = CalculatedProperty() - + calculated_property: Optional[CalculatedProperty] = CalculatedProperty() + #pass