|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -"""module specifying the database models""" |
| 3 | +"""module defining the database models""" |
4 | 4 |
|
5 | 5 | from typing import Any, Callable, Dict, List, Tuple, Union
|
6 | 6 | from operator import attrgetter
|
| 7 | +import enum |
7 | 8 | import math
|
8 | 9 | import urllib.parse
|
9 | 10 |
|
10 | 11 | import numpy as np
|
11 |
| -from sqlalchemy import Column, Boolean, Integer, String, Float, ForeignKey |
| 12 | +from sqlalchemy import Column, Boolean, Integer, String, Float, ForeignKey, Text, Enum |
12 | 13 | from sqlalchemy.orm import declarative_base, relationship, reconstructor
|
13 | 14 | from sqlalchemy.ext.associationproxy import association_proxy
|
14 | 15 | from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method
|
|
34 | 35 | "IonicRadius",
|
35 | 36 | "OxidationState",
|
36 | 37 | "Isotope",
|
| 38 | + "PropertyMetadata", |
37 | 39 | "Series",
|
38 | 40 | "ScreeningConstant",
|
39 | 41 | ]
|
@@ -731,6 +733,54 @@ def __repr__(self) -> str:
|
731 | 733 | )
|
732 | 734 |
|
733 | 735 |
|
| 736 | +class ValueOrigin(enum.Enum): |
| 737 | + "Options for the origin of the property value." |
| 738 | + |
| 739 | + STORED = "stored" |
| 740 | + COMPUTED = "computed" |
| 741 | + |
| 742 | + |
| 743 | +class PropertyMetadata(Base): |
| 744 | + """Metadata for properties of elements and isotopes. |
| 745 | +
|
| 746 | + Args: |
| 747 | + annotations (str): Additional information about the property. |
| 748 | + attribute_name (str): Name of the attribute of the ORM class. |
| 749 | + category (str): Category of the property. |
| 750 | + citation_keys (str): Comma separated list of citation keys. See references.bib for full bibliography. |
| 751 | + class_name (str): Name of the ORM class. |
| 752 | + column_name (str): Name of the column in the database. |
| 753 | + description (str): Description of the property. |
| 754 | + table_name (str): Name of the table in the database. |
| 755 | + unit (str): Unit of the property. |
| 756 | + value_origin (ValueOrigin): Origin of the value, either stored or computed. |
| 757 | + """ |
| 758 | + |
| 759 | + __tablename__ = "propertymetadata" |
| 760 | + |
| 761 | + id = Column(Integer, primary_key=True) |
| 762 | + annotations = Column(Text) |
| 763 | + attribute_name = Column(String, nullable=False) |
| 764 | + category = Column(String) |
| 765 | + citation_keys = Column(String) |
| 766 | + class_name = Column(String, nullable=False) |
| 767 | + column_name = Column(String, nullable=True) |
| 768 | + description = Column(Text, nullable=False) |
| 769 | + table_name = Column(String, nullable=True) |
| 770 | + unit = Column(String) |
| 771 | + value_origin = Column(Enum(ValueOrigin), nullable=False) |
| 772 | + |
| 773 | + def __repr__(self) -> str: |
| 774 | + return "%s(\n%s)" % ( |
| 775 | + self.__class__.__name__, |
| 776 | + " ".join( |
| 777 | + "\t%s=%r,\n" % (key, getattr(self, key)) |
| 778 | + for key in sorted(self.__dict__.keys()) |
| 779 | + if not key.startswith("_") |
| 780 | + ), |
| 781 | + ) |
| 782 | + |
| 783 | + |
734 | 784 | def fetch_attrs_for_group(attrs: List[str], group: int = 18) -> Tuple[List[Any]]:
|
735 | 785 | """
|
736 | 786 | A convenience function for getting a specified attribute for all
|
|
0 commit comments