diff --git a/.gitignore b/.gitignore index f598309..bc087d6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,8 @@ _static _templates # ipython checkpoints -docs/source/**/.ipynb_checkpoints \ No newline at end of file +docs/source/**/.ipynb_checkpoints +docs/**/.ipynb_checkpoints +docs/**/.ipynb_checkpoints +docs/.ipynb_checkpoints +docs/examples/.ipynb_checkpoints \ No newline at end of file diff --git a/Data/iron.yml b/Data/fe.yaml similarity index 76% rename from Data/iron.yml rename to Data/fe.yaml index 854a7ee..f76a566 100644 --- a/Data/iron.yml +++ b/Data/fe.yaml @@ -5,7 +5,7 @@ meta: comment: maybe there is something to say here last_updated: 2020-04-28 references: - @article{curtiss2013unicorn, + '@article{curtiss2013unicorn, author = "Curtiss, Michael and Becker, Iain and Bosman, Tudor and Doroshenko, Sergey and Grijincu, Lucian and Jackson, Tom and Kunnatur, Sandhya and Lassen, Soren and Pronin, Philip and Sankar, Sriram and others", title = "Unicorn: A system for searching the social graph", journal = "Proceedings of the VLDB Endowment", @@ -15,7 +15,7 @@ meta: year = "2013", publisher = "VLDB Endowment", doi = "10.14778/2536222.2536239" - } + }' data: thermal_conductivity: curtiss2013unicorn: @@ -25,11 +25,9 @@ data: comment: some value comment here refractive_index: curtiss2013unicorn: - value: - wavelength: - values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...] - arg_values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...] - arg_unit: nm - comment: maybe one can write a fit of the data here + value: [1+2j, 2+4j] + arg_value: [800] + arg_unit: nm + comment: maybe one can write a fit of the data here unit: '' comment: n = n' + i k \ No newline at end of file diff --git a/Data/template.yml b/Data/gd.yaml similarity index 100% rename from Data/template.yml rename to Data/gd.yaml diff --git a/Data/ni.yaml b/Data/ni.yaml new file mode 100644 index 0000000..4f50236 --- /dev/null +++ b/Data/ni.yaml @@ -0,0 +1,51 @@ +meta: + name: nickel + formula: Ni + last_updated: 7272181873150 + description: + comment: + references: + '@article{wikipedia, + author = "Wikipedia", + title = "Nickel", + url = "https://de.wikipedia.org/wiki/Nickel" + } + + @online{ri_info, + author = "refractiveindex.info", + title = "Nickel", + urls = "https://refractiveindex.info/?shelf=main&book=Ni&page=Johnson" + }' + +data: + thermal_conductivity: + wikipedia: + value: 91 + units: W/(mK) + ri_info: + value: 90 + units: W/(mK) + + molar_volume: + wikipedia: + value: 6.59e-06 + units: m^3/mol + + boiling_point: + wikipedia: + value: 3003.0 + units: K + + melting_point: + wikipedia: + value: 1728.0 + units: K + + refractive_index: + ri_info: + value: 1+2j + arg_value: 0.188 + arg_name: Wavelength + arg_unit: µm + + diff --git a/Data/nickel.yml b/Data/nickel.yml deleted file mode 100644 index 55d5e1c..0000000 --- a/Data/nickel.yml +++ /dev/null @@ -1,53 +0,0 @@ -Material name: nickel -References: -- https://de.wikipedia.org/wiki/Nickel -- https://refractiveindex.info/?shelf=main&book=Ni&page=Johnson -Comment: Testfile -Data: -- Parameter name: Thermal conductivity - Comment: '' - Reference number: 1 - Units: [W/(mK)] - Value names: [Thermal conductivity] - Values: - - [91.0] -- Parameter name: Molar volume - Comment: '' - Reference number: 1 - Units: [m^3/mol] - Value names: [''] - Values: - - [6.59e-06] -- Parameter name: Boiling point - Comment: '' - Reference number: 1 - Units: [K] - Value names: [Boiling point] - Values: - - [3003.0] -- Parameter name: Melting point - Comment: '' - Reference number: 1 - Units: [K] - Value names: [Melting point] - Values: - - [1728.0] -- Parameter name: Refractive index - Comment: '' - Reference number: 2 - Units: [µm, '-', '-'] - Value names: [wavelength, n, k] - Values: - - [0.188, 0.192, 0.195, 0.199, 0.203, 0.207, 0.212, 0.216, 0.221, 0.226, 0.231, - 0.237, 0.243, 0.249, 0.255, 0.262, 0.269, 0.276, 0.284, 0.292, 0.301, 0.311, 0.32, - 0.332, 0.342, 0.354, 0.368, 0.381, 0.397, 0.413, 0.431, 0.451, 0.471, 0.496, 0.521, - 0.549, 0.582, 0.617, 0.659, 0.704, 0.756, 0.821, 0.892, 0.984, 1.088, 1.216, 1.393, - 1.61, 1.937] - - [1.26, 1.29, 1.29, 1.28, 1.28, 1.29, 1.32, 1.34, 1.38, 1.43, 1.49, 1.57, 1.65, - 1.73, 1.82, 1.89, 1.96, 2.01, 2.03, 2.03, 2.02, 2.01, 1.93, 1.84, 1.78, 1.74, - 1.7, 1.72, 1.72, 1.7, 1.71, 1.73, 1.78, 1.82, 1.85, 1.92, 1.96, 1.99, 1.99, 2.06, - 2.13, 2.26, 2.4, 2.48, 2.65, 2.79, 2.96, 3.14, 3.47] - - [1.6, 1.64, 1.69, 1.75, 1.82, 1.89, 1.96, 2.02, 2.09, 2.15, 2.2, 2.25, 2.29, 2.31, - 2.32, 2.3, 2.29, 2.26, 2.23, 2.2, 2.18, 2.18, 2.19, 2.22, 2.26, 2.32, 2.4, 2.48, - 2.57, 2.69, 2.82, 2.95, 3.09, 3.25, 3.42, 3.61, 3.8, 4.02, 4.26, 4.5, 4.73, 4.97, - 5.23, 5.55, 5.93, 6.43, 7.08, 7.96, 9.09] diff --git a/Data/template.yaml b/Data/template.yaml new file mode 100644 index 0000000..18224e6 --- /dev/null +++ b/Data/template.yaml @@ -0,0 +1,12 @@ +Material name: '' +References: +- '' +Comment: '' +Data: +- Parameter name: '' + Comment: '' + Reference number: 1 + Units: [] + Value names: [] + Values: + - [] diff --git a/README.md b/README.md index 24767e9..b60f59b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # MBI Material Database Concept -Due to the general demand for collecting, storing, and exchanging material parameters, we provide a text file based solution as well as several Python scripts and GUIs to read, change, and store material parameters. +Due to the general demand for collecting, storing, and exchanging material parameters, we provide a text-file-based solution, as well as several Python scripts and GUIs to read, change, and store material parameters. -Initially, we will only support [YAML](https://en.wikipedia.org/wiki/YAML) as data source, but the general design will allow also for other data sources, such as SQL databases or other file formats, e.g. XML or JSON. +Initially, we will only support the [YAML](https://en.wikipedia.org/wiki/YAML) format as a data source, but the general design will allow also for other data sources, such as SQL databases or other file formats, e.g. XML or JSON. ## YAML Format @@ -47,12 +47,13 @@ data: ``` First, there is `meta` section which holds meta-data of the material. -Most importantly, the must be references defined, in order to link paramters to them. -The `references` entrie must be a plain `bibtex` entry which can hold any type of reference and as many as necessary. +Most importantly, there must be `references` defined, in order to link paramters to them. +The `references` entry must be in plain `bibtex` format, which can hold any type of reference and as many as necessary. +Further, one must include a `last_updated` field. In the `data` section the actual physical parameters are declared. -It is possible to have multiple values stored for a single parameter, by indexing each by a `citation_key` which must be defined above in the `meta` section. -The actual parmaters, must have `value` and `unit` as well as optional `uncertainty` and `comment`. +It is possible to have multiple values stored for a single parameter, by indexing each by a `citation_key`, which must be defined above in the `meta` section. +The actual parmaters, must have `value` and `unit` and can optionally have `uncertainty` and `comment`. In case of a functional dependence of a parameter, the name of the `argument` must be given as new index. The actual parameter `values`, the `arg_values` and `arg_unit` are mandatory. The `comment` is optional. @@ -60,12 +61,11 @@ With this format even multiple functional dependencies are possible from one and ## Python Scripts -Although the YAML file format allows for human readability and does not require any programmatic access, we provide several Python modules in order to inteact with the material database. +The YAML file format allows for human readability and does not require any programmatic access. +However, we provide several Python (other languages such as MATLAB can be implemented in the future as well) modules in order to inteact with the material database: -We first stick to Python but other languages such as MATLAB can be implemented in the future as well. - -We divide the modules into a `Parser` module which is dedicated for reading and writing data from and to e.g. a YAML file. -The data must be provided as a `dict` in Python with a well defined structure. +The `Parser` module is dedicated for reading and writing data from and to e.g. a YAML file. +New data must be provided as a `dict` in Python with a well-defined structure. The `Material` module implements a class for `Material`, `Paramter`, and `References` and should allow for easy interaction in a Python script with the material database. @@ -76,11 +76,11 @@ An example of programmatic access to the database could look like this: ```python import material_database as md -parser = md.PyYamlParser('/my/path/to/yaml/files') +parser = md.parser.PyYamlParser('/my/path/to/yaml/files') -iron = md.Material(parser.read_from_file(iron.yaml)) +iron = md.Material(parser.load('fe'), log_level=10) -print(iron.thermal_conductivity) -.. 80 +print(iron.thermal_conductivity['curtisss2013unicorn'].value) +..80 ``` \ No newline at end of file diff --git a/docs/examples/simple_test.ipynb b/docs/examples/simple_test.ipynb index 79ce9a2..940c3dc 100644 --- a/docs/examples/simple_test.ipynb +++ b/docs/examples/simple_test.ipynb @@ -2,9 +2,18 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], "source": [ "# configure to autoload all extension\n", "%load_ext autoreload\n", @@ -13,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -23,9 +32,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO :: base path of PyYamlParser set to: ./\n" + ] + } + ], "source": [ "yaml_data_path = './'\n", "yaml_parser = md.parser.PyYamlParser(yaml_data_path, log_level=20)" @@ -33,20 +50,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "material_data = yaml_parser.load('test_material')" + "test_material.thermal_conductivity['curtiss2013unicorn'].value" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "82" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "material_data['meta']['references']['curtiss2013unicorn']" + "test_material.thermal_conductivity['aad2015combined'].value" ] }, { @@ -54,27 +93,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "test_material = md.Material(material_data, log_level=20)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "test_material.references['curtiss2013unicorn'].dump()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "test_material.parameters['thermal_conductivity'].dump()" - ] + "source": [] } ], "metadata": { @@ -93,7 +112,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/docs/examples/test_material.yml b/docs/examples/test_material.yaml similarity index 98% rename from docs/examples/test_material.yml rename to docs/examples/test_material.yaml index 6a8dd0f..db7ec70 100644 --- a/docs/examples/test_material.yml +++ b/docs/examples/test_material.yaml @@ -4,7 +4,7 @@ meta: description: here is some text describing the material comment: some comments references: - '@article{aad2015combined, + '@article{aad2015combined, author = {Aad, Georges and Abbott, B and Abdallah, J and Abdinov, O and Aben, R and Abolins, M and AbouZeid, OS and Abramowicz, H and Abreu, H and Abreu, R and others}, journal = {Physical review letters}, number = {19}, diff --git a/docs/test_notebook.ipynb b/docs/test_notebook.ipynb index ba8b5ec..590bd2c 100644 --- a/docs/test_notebook.ipynb +++ b/docs/test_notebook.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -25,11 +25,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "db_path = r'C:\\Users\\loc_steinbac\\Documents\\5-Code\\1-git_repos\\MaterialDatabase\\docs\\examples'\n", + "db_path = r'C:\\Users\\borchert\\Documents\\repos\\MaterialDatabase\\docs\\examples'\n", "material = 'test_material'" ] }, @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -62,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -88,9 +88,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Reference cheng2015generalized: {'author': 'Cheng, Xinyue and Zou, Yangyang', 'journal': 'Differential Geometry-Dynamical Systems', 'pages': '38--48', 'title': 'The generalized unicorn problem in Finsler geometry', 'volume': '17', 'year': '2015', 'ENTRYTYPE': 'article'}\n", + "Reference aad2015combined: {'author': 'Aad, Georges and Abbott, B and Abdallah, J and Abdinov, O and Aben, R and Abolins, M and AbouZeid, OS and Abramowicz, H and Abreu, H and Abreu, R and others', 'journal': 'Physical review letters', 'pages': '191803', 'title': 'Combined Measurement of the Higgs Boson Mass in p p Collisions at s= 7 and 8 TeV with the ATLAS and CMS Experiments', 'volume': '114', 'year': '2015', 'ENTRYTYPE': 'article', 'publisher': 'APS', 'number': '19'}\n" + ] + } + ], "source": [ "print('Reference %s: %s'%(\"cheng2015generalized\",str(data.cheng2015generalized.dump())))\n", "print('Reference %s: %s'%(str(data.list_references()[0]),str(getattr(data,data.list_references()[0]).dump())))" @@ -105,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -131,9 +140,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added parameter wavelength with reference curtiss2013unicorn correctly to database.\n" + ] + }, + { + "ename": "TypeError", + "evalue": "getattr(): attribute name must be string", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_parameter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnewPara\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32mc:\\users\\borchert\\documents\\repos\\materialdatabase\\material_database\\models\\material.py\u001b[0m in \u001b[0;36mvalidate\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 137\u001b[0m \u001b[0mref_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlist_references\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 138\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mpar\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpar_list\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 139\u001b[1;33m \u001b[0mpar_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpar\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 140\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mpar_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpar_data\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpar_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 141\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mpar_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mref_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: getattr(): attribute name must be string" + ] + } + ], "source": [ "newPara = md.Parameter('wavelength','curtiss2013unicorn')\n", "newPara.addValueList('lambda',[10,20,304,55])\n", @@ -151,14 +180,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "getattr(): attribute name must be string", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdata_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdump\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0myaml_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0myaml_parser\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdump\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata_dict\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\users\\borchert\\documents\\repos\\materialdatabase\\material_database\\models\\material.py\u001b[0m in \u001b[0;36mdump\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 97\u001b[0m \"\"\"\n\u001b[1;32m---> 98\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 99\u001b[0m \u001b[0mmat_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 100\u001b[0m \u001b[0mpar_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlist_parameters\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\users\\borchert\\documents\\repos\\materialdatabase\\material_database\\models\\material.py\u001b[0m in \u001b[0;36mvalidate\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 137\u001b[0m \u001b[0mref_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlist_references\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 138\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mpar\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpar_list\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 139\u001b[1;33m \u001b[0mpar_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpar\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 140\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mpar_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpar_data\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpar_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 141\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mpar_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mref_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: getattr(): attribute name must be string" + ] + } + ], "source": [ "data_dict = data.dump()\n", "\n", "yaml_file = yaml_parser.dump(data_dict)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -177,7 +227,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.0" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/material_database/models/material.py b/material_database/models/material.py index 5acb07e..d1ba440 100644 --- a/material_database/models/material.py +++ b/material_database/models/material.py @@ -85,7 +85,7 @@ def build_from_dict(self, material_data): tmp_par_dict = {} for sub_par_name, sub_par_data in par_data.items(): sub_name = name_to_identifer(sub_par_name) - tmp_par_dict[sub_name] = Parameter(name,sub_name, sub_par_data, log_level=self.log_level) + tmp_par_dict[sub_name] = Parameter(name, sub_name, sub_par_data, log_level=self.log_level) self.__dict__[name] = tmp_par_dict self.logger.info('added parameter with name {:s}'.format(name)) diff --git a/material_database/parser/pyYamlParser.py b/material_database/parser/pyYamlParser.py index e91fd8b..84445a5 100644 --- a/material_database/parser/pyYamlParser.py +++ b/material_database/parser/pyYamlParser.py @@ -56,10 +56,10 @@ def load(self, material): """ full_file_name = path.join(path.abspath(self.base_path), - material + '.yml') + material + '.yaml') # read yaml file with open(full_file_name, 'r') as file: - material_data = yaml.load(file, Loader=yaml.FullLoader) + material_data = yaml.unsafe_load(file) # add filename as ID to dict material_data['ID'] = material @@ -69,7 +69,29 @@ def load(self, material): bibtex = material_data['meta']['references'] # convert bibtex into list of dicts - bib_list = bibtexparser.loads(bibtex).entries + ## these two lines also allow for other types than the standard: + + # 'article', + # 'book', + # 'booklet', + # 'conference', + # 'inbook', + # 'incollection', + # 'inproceedings', + # 'manual', + # 'mastersthesis', + # 'misc', + # 'phdthesis', + # 'proceedings', + # 'techreport', + # 'unpublished' + + parser = bibtexparser.bparser.BibTexParser(common_strings=False) + parser.ignore_nonstandard_types = False + #parser.homogenise_fields = False + + bib_list = bibtexparser.loads(bibtex, parser).entries + # create dicts with bibtex ID as key bib_dict = {} for bibtex_entry in bib_list: @@ -80,6 +102,17 @@ def load(self, material): # replace bibtex string with dict material_data['meta']['references'] = bib_dict + # This part fixes the issue that pyYaml imports complex numbers as strings. + # Manually stepping throuh the whole array and turns strings into complex numbers + for prop_key, prop_value in material_data['data'].items(): + for cite_key, cite_value in prop_value.items(): + if type(cite_value['value']) == str: + self.logger.info(cite_value['value']) + material_data['data'][prop_key][cite_key]['value'] = complex(cite_value['value'].replace("i", "j").replace(" ", "")) + elif type(cite_value['value']) == list and type(cite_value['value'][0]) == str: + material_data['data'][prop_key][cite_key]['value'] = [complex(v.replace("i", "j").replace(" ", "")) for v in cite_value['value']] + else: + pass return material_data def dump(self, material_data): @@ -175,7 +208,7 @@ def dump(self, material_data): full_file_name = path.join(path.abspath(self.base_path), - meta_dict['name'].replace(' ','_') + '.yml') + meta_dict['name'].replace(' ','_') + '.yaml') # read yaml file f = open(full_file_name, "w") f.write(yamlFile)