├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── docs ├── Makefile └── src │ ├── conf.py │ └── index.rst ├── pypif ├── __init__.py ├── obj │ ├── __init__.py │ ├── common │ │ ├── __init__.py │ │ ├── classification.py │ │ ├── display_item.py │ │ ├── file_reference.py │ │ ├── id.py │ │ ├── instrument.py │ │ ├── license.py │ │ ├── method.py │ │ ├── name.py │ │ ├── pages.py │ │ ├── person.py │ │ ├── pio.py │ │ ├── process_step.py │ │ ├── property.py │ │ ├── quantity.py │ │ ├── rcl.py │ │ ├── reference.py │ │ ├── scalar.py │ │ ├── software.py │ │ ├── source.py │ │ ├── tests │ │ │ ├── test_file_reference.py │ │ │ └── test_value.py │ │ └── value.py │ └── system │ │ ├── __init__.py │ │ ├── chemical │ │ ├── __init__.py │ │ ├── alloy │ │ │ ├── __init__.py │ │ │ ├── alloy.py │ │ │ └── alloy_phase.py │ │ ├── chemical_system.py │ │ └── common │ │ │ ├── __init__.py │ │ │ └── composition.py │ │ ├── system.py │ │ └── tests │ │ └── test_system.py ├── pif.py ├── tests │ └── test_pif.py └── util │ ├── __init__.py │ ├── case.py │ ├── pif_encoder.py │ ├── serializable.py │ └── tests │ └── test_case.py ├── requirements.txt ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .idea 3 | build 4 | .DS_Store 5 | dist 6 | pypif.egg-info* 7 | docs/build 8 | docs/source 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | python: 4 | - '2.7' 5 | - '3.4' 6 | - '3.5' 7 | - '3.6' 8 | install: 9 | - pip install pytest 10 | - python setup.py install 11 | script: 12 | - py.test pypif --verbose 13 | deploy: 14 | provider: pypi 15 | user: CitrineInformatics 16 | password: 17 | secure: QaxOL3h4n7YqS3isvY63S6ejnEGqXJDobMlhxXr158pHKChjKzuf46JSRXAPEbiq/JR7H+m3qWLaTABBxvjU0jjKIXNVN0u+dG+pVBN0ZAfS18WspTYsdjH2eIR6AbCOsvA//dpohuz5C/oJHco2ZB1QiOVSsQsWXCUQk0mIXeXfRLvJtkuVigijiayRAnpDx37/icTvzgsN/H96bGk/5Ms/sV5V2tWp6KtJnMhFa0thQXmF8MRyfeqkqh56qJcfPHL7HHO1p/PEbUrZ2jrPo0ErKKGhWOPVBmkklPDASAsbXBDy+2twHAMn6f1QDk243+QexRjfET1b0XZrGSIH90dyvvJg99m0HbU5/44ZN1t9UYY9f5cnm+bmeG8ApRWuDUpIFEGCulv54yk0s4f86oknW7z29z1fUhMcYUhnTIy/JlO5Me+dlcsip3NsMo0B78/OqnXmI5UyphWRbJps4+0b9NPYoUEzPibfEMQVjEw8H4UEc0DIbnwKyk8C18OWo3l9OtuZ8jzWM5owEfTDCjSw6fowHy9AhJ+of0JFv6CN6+1GHf5rXDJzMLAyyYLniRr4PzFii9YW+2moLsQCMbRsqI/CPM8Q/x3vPm4b3I8cdnJ+xUjFNQejUSkhySL0uEr9FRGdyrW2n712T0FZvZL7Y9wz+9KhdTUqtYIyo2w= 18 | on: 19 | distributions: sdist bdist_wheel 20 | repo: CitrineInformatics/pypif 21 | branch: master 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pypif 2 | ![status](https://travis-ci.org/CitrineInformatics/pypif.svg?branch=master) 3 | ![PyPI version](https://badge.fury.io/py/pypif.svg) 4 | 5 | ## About 6 | 7 | Tools to serialize and deserialize to and from the [PIF](http://citrine.io/pif) schema. 8 | This package provides python objects for each object in the PIF schema and methods 9 | for serialization and deserialization. 10 | 11 | There is a companion Java library called [JPIF](https://github.com/CitrineInformatics/jpif). 12 | 13 | ## Installation 14 | 15 | ### Requirements 16 | 17 | * Python >= 2.7 or >= 3.3 18 | 19 | ### Setup 20 | 21 | `pypif` is published on [PyPI](https://pypi.python.org/pypi/pypif), so it can be installed with `pip`: 22 | ```shell 23 | $ pip install pypif 24 | ``` 25 | 26 | ## Example 27 | 28 | The following example creates a PIF record that saves the band gap of MgO2 as equal to 7.8 eV. 29 | 30 | ```python 31 | from pypif import pif 32 | from pypif.obj import * 33 | 34 | 35 | chemical_system = ChemicalSystem() 36 | chemical_system.chemical_formula = 'MgO2' 37 | 38 | band_gap = Property() 39 | band_gap.name = 'Band gap' 40 | band_gap.scalars = 7.8 41 | band_gap.units = 'eV' 42 | 43 | chemical_system.properties = band_gap 44 | 45 | print(pif.dumps(chemical_system, indent=4)) 46 | ``` 47 | 48 | This example will serialize to the following JSON representation: 49 | 50 | ```json 51 | { 52 | "category": "system.chemical", 53 | "chemicalFormula": "MgO2", 54 | "properties": { 55 | "units": "eV", 56 | "name": "Band gap", 57 | "scalars": [ 58 | { 59 | "value": 7.8 60 | } 61 | ] 62 | } 63 | } 64 | ``` 65 | 66 | # Schema 67 | 68 | A detailed discussion of the PIF schema and usage are available at [http://citrine.io/pif](http://citrine.io/pif). -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 16 | 17 | .PHONY: help 18 | help: 19 | @echo "Please use \`make ' where is one of" 20 | @echo " html to make standalone HTML files" 21 | @echo " dirhtml to make HTML files named index.html in directories" 22 | @echo " singlehtml to make a single large HTML file" 23 | @echo " pickle to make pickle files" 24 | @echo " json to make JSON files" 25 | @echo " htmlhelp to make HTML files and a HTML help project" 26 | @echo " qthelp to make HTML files and a qthelp project" 27 | @echo " applehelp to make an Apple Help Book" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " epub3 to make an epub3" 31 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 32 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 33 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 34 | @echo " text to make text files" 35 | @echo " man to make manual pages" 36 | @echo " texinfo to make Texinfo files" 37 | @echo " info to make Texinfo files and run them through makeinfo" 38 | @echo " gettext to make PO message catalogs" 39 | @echo " changes to make an overview of all changed/added/deprecated items" 40 | @echo " xml to make Docutils-native XML files" 41 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 42 | @echo " linkcheck to check all external links for integrity" 43 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 44 | @echo " coverage to run coverage check of the documentation (if enabled)" 45 | @echo " dummy to check syntax errors of document sources" 46 | 47 | .PHONY: gh-pages 48 | gh-pages: clean html 49 | cd build/html && \ 50 | git init && \ 51 | git checkout -b gh-pages && \ 52 | git add . && \ 53 | git commit -m "updating sphinx" && \ 54 | git remote add upstream git@github.com:CitrineInformatics/pypif.git && \ 55 | git push upstream gh-pages --force 56 | 57 | .PHONY: clean 58 | clean: 59 | rm -rf $(BUILDDIR)/* 60 | rm -rf source 61 | 62 | .PHONY: apidoc 63 | apidoc: clean 64 | cp -r src source 65 | sphinx-apidoc -e ../pypif -o source 66 | 67 | .PHONY: html 68 | html: apidoc 69 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 70 | @echo 71 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 72 | 73 | .PHONY: dirhtml 74 | dirhtml: 75 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 76 | @echo 77 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 78 | 79 | .PHONY: singlehtml 80 | singlehtml: 81 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 82 | @echo 83 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 84 | 85 | .PHONY: pickle 86 | pickle: 87 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 88 | @echo 89 | @echo "Build finished; now you can process the pickle files." 90 | 91 | .PHONY: json 92 | json: 93 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 94 | @echo 95 | @echo "Build finished; now you can process the JSON files." 96 | 97 | .PHONY: htmlhelp 98 | htmlhelp: 99 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 100 | @echo 101 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 102 | ".hhp project file in $(BUILDDIR)/htmlhelp." 103 | 104 | .PHONY: qthelp 105 | qthelp: 106 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 107 | @echo 108 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 109 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 110 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pypif.qhcp" 111 | @echo "To view the help file:" 112 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pypif.qhc" 113 | 114 | .PHONY: applehelp 115 | applehelp: 116 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 117 | @echo 118 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 119 | @echo "N.B. You won't be able to view it unless you put it in" \ 120 | "~/Library/Documentation/Help or install it in your application" \ 121 | "bundle." 122 | 123 | .PHONY: devhelp 124 | devhelp: 125 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 126 | @echo 127 | @echo "Build finished." 128 | @echo "To view the help file:" 129 | @echo "# mkdir -p $$HOME/.local/share/devhelp/pypif" 130 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pypif" 131 | @echo "# devhelp" 132 | 133 | .PHONY: epub 134 | epub: 135 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 136 | @echo 137 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 138 | 139 | .PHONY: epub3 140 | epub3: 141 | $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 142 | @echo 143 | @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." 144 | 145 | .PHONY: latex 146 | latex: 147 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 148 | @echo 149 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 150 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 151 | "(use \`make latexpdf' here to do that automatically)." 152 | 153 | .PHONY: latexpdf 154 | latexpdf: 155 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 156 | @echo "Running LaTeX files through pdflatex..." 157 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 158 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 159 | 160 | .PHONY: latexpdfja 161 | latexpdfja: 162 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 163 | @echo "Running LaTeX files through platex and dvipdfmx..." 164 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 165 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 166 | 167 | .PHONY: text 168 | text: 169 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 170 | @echo 171 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 172 | 173 | .PHONY: man 174 | man: 175 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 176 | @echo 177 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 178 | 179 | .PHONY: texinfo 180 | texinfo: 181 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 182 | @echo 183 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 184 | @echo "Run \`make' in that directory to run these through makeinfo" \ 185 | "(use \`make info' here to do that automatically)." 186 | 187 | .PHONY: info 188 | info: 189 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 190 | @echo "Running Texinfo files through makeinfo..." 191 | make -C $(BUILDDIR)/texinfo info 192 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 193 | 194 | .PHONY: gettext 195 | gettext: 196 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 197 | @echo 198 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 199 | 200 | .PHONY: changes 201 | changes: 202 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 203 | @echo 204 | @echo "The overview file is in $(BUILDDIR)/changes." 205 | 206 | .PHONY: linkcheck 207 | linkcheck: 208 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 209 | @echo 210 | @echo "Link check complete; look for any errors in the above output " \ 211 | "or in $(BUILDDIR)/linkcheck/output.txt." 212 | 213 | .PHONY: doctest 214 | doctest: 215 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 216 | @echo "Testing of doctests in the sources finished, look at the " \ 217 | "results in $(BUILDDIR)/doctest/output.txt." 218 | 219 | .PHONY: coverage 220 | coverage: 221 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 222 | @echo "Testing of coverage in the sources finished, look at the " \ 223 | "results in $(BUILDDIR)/coverage/python.txt." 224 | 225 | .PHONY: xml 226 | xml: 227 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 228 | @echo 229 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 230 | 231 | .PHONY: pseudoxml 232 | pseudoxml: 233 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 234 | @echo 235 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 236 | 237 | .PHONY: dummy 238 | dummy: 239 | $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy 240 | @echo 241 | @echo "Build finished. Dummy builder generates no files." 242 | -------------------------------------------------------------------------------- /docs/src/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # pypif documentation build configuration file, created by 5 | # sphinx-quickstart on Mon Jan 23 09:27:47 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | # import os 21 | # import sys 22 | # sys.path.insert(0, os.path.abspath('.')) 23 | import os 24 | import sys 25 | sys.path.insert(0, os.path.abspath('../../pypif')) 26 | 27 | # -- General configuration ------------------------------------------------ 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | # 31 | # needs_sphinx = '1.0' 32 | 33 | # Add any Sphinx extension module names here, as strings. They can be 34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 35 | # ones. 36 | extensions = [ 37 | 'sphinx.ext.autodoc', 38 | 'sphinx.ext.intersphinx', 39 | 'sphinx.ext.todo', 40 | 'sphinx.ext.mathjax', 41 | 'sphinx.ext.viewcode', 42 | 'sphinx.ext.githubpages', 43 | ] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix(es) of source filenames. 49 | # You can specify multiple suffix as a list of string: 50 | # 51 | # source_suffix = ['.rst', '.md'] 52 | source_suffix = '.rst' 53 | 54 | # The encoding of source files. 55 | # 56 | # source_encoding = 'utf-8-sig' 57 | 58 | # The master toctree document. 59 | master_doc = 'index' 60 | 61 | # General information about the project. 62 | project = 'pypif' 63 | copyright = '2017, Citrine Informatics' 64 | author = 'Kyle Michel, Max Hutchinson' 65 | 66 | # The version info for the project you're documenting, acts as replacement for 67 | # |version| and |release|, also used in various other places throughout the 68 | # built documents. 69 | # 70 | # The short X.Y version. 71 | version = '2.1.1' 72 | # The full version, including alpha/beta/rc tags. 73 | release = version 74 | 75 | # The language for content autogenerated by Sphinx. Refer to documentation 76 | # for a list of supported languages. 77 | # 78 | # This is also used if you do content translation via gettext catalogs. 79 | # Usually you set "language" from the command line for these cases. 80 | language = None 81 | 82 | # There are two options for replacing |today|: either, you set today to some 83 | # non-false value, then it is used: 84 | # 85 | # today = '' 86 | # 87 | # Else, today_fmt is used as the format for a strftime call. 88 | # 89 | # today_fmt = '%B %d, %Y' 90 | 91 | # List of patterns, relative to source directory, that match files and 92 | # directories to ignore when looking for source files. 93 | # This patterns also effect to html_static_path and html_extra_path 94 | exclude_patterns = [] 95 | 96 | # The reST default role (used for this markup: `text`) to use for all 97 | # documents. 98 | # 99 | # default_role = None 100 | 101 | # If true, '()' will be appended to :func: etc. cross-reference text. 102 | # 103 | # add_function_parentheses = True 104 | 105 | # If true, the current module name will be prepended to all description 106 | # unit titles (such as .. function::). 107 | # 108 | # add_module_names = True 109 | 110 | # If true, sectionauthor and moduleauthor directives will be shown in the 111 | # output. They are ignored by default. 112 | # 113 | # show_authors = False 114 | 115 | # The name of the Pygments (syntax highlighting) style to use. 116 | pygments_style = 'sphinx' 117 | 118 | # A list of ignored prefixes for module index sorting. 119 | # modindex_common_prefix = [] 120 | 121 | # If true, keep warnings as "system message" paragraphs in the built documents. 122 | # keep_warnings = False 123 | 124 | # If true, `todo` and `todoList` produce output, else they produce nothing. 125 | todo_include_todos = True 126 | 127 | 128 | # -- Options for HTML output ---------------------------------------------- 129 | 130 | # The theme to use for HTML and HTML Help pages. See the documentation for 131 | # a list of builtin themes. 132 | # 133 | html_theme = 'classic' 134 | 135 | # Theme options are theme-specific and customize the look and feel of a theme 136 | # further. For a list of options available for each theme, see the 137 | # documentation. 138 | # 139 | # html_theme_options = {} 140 | 141 | # Add any paths that contain custom themes here, relative to this directory. 142 | # html_theme_path = [] 143 | 144 | # The name for this set of Sphinx documents. 145 | # " v documentation" by default. 146 | # 147 | # html_title = 'pypif v1.1.1' 148 | 149 | # A shorter title for the navigation bar. Default is the same as html_title. 150 | # 151 | # html_short_title = None 152 | 153 | # The name of an image file (relative to this directory) to place at the top 154 | # of the sidebar. 155 | # 156 | # html_logo = None 157 | 158 | # The name of an image file (relative to this directory) to use as a favicon of 159 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 160 | # pixels large. 161 | # 162 | # html_favicon = None 163 | 164 | # Add any paths that contain custom static files (such as style sheets) here, 165 | # relative to this directory. They are copied after the builtin static files, 166 | # so a file named "default.css" will overwrite the builtin "default.css". 167 | html_static_path = ['_static'] 168 | 169 | # Add any extra paths that contain custom files (such as robots.txt or 170 | # .htaccess) here, relative to this directory. These files are copied 171 | # directly to the root of the documentation. 172 | # 173 | # html_extra_path = [] 174 | 175 | # If not None, a 'Last updated on:' timestamp is inserted at every page 176 | # bottom, using the given strftime format. 177 | # The empty string is equivalent to '%b %d, %Y'. 178 | # 179 | # html_last_updated_fmt = None 180 | 181 | # If true, SmartyPants will be used to convert quotes and dashes to 182 | # typographically correct entities. 183 | # 184 | # html_use_smartypants = True 185 | 186 | # Custom sidebar templates, maps document names to template names. 187 | # 188 | # html_sidebars = {} 189 | 190 | # Additional templates that should be rendered to pages, maps page names to 191 | # template names. 192 | # 193 | # html_additional_pages = {} 194 | 195 | # If false, no module index is generated. 196 | # 197 | # html_domain_indices = True 198 | 199 | # If false, no index is generated. 200 | # 201 | # html_use_index = True 202 | 203 | # If true, the index is split into individual pages for each letter. 204 | # 205 | # html_split_index = False 206 | 207 | # If true, links to the reST sources are added to the pages. 208 | # 209 | # html_show_sourcelink = True 210 | 211 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 212 | # 213 | # html_show_sphinx = True 214 | 215 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 216 | # 217 | # html_show_copyright = True 218 | 219 | # If true, an OpenSearch description file will be output, and all pages will 220 | # contain a tag referring to it. The value of this option must be the 221 | # base URL from which the finished HTML is served. 222 | # 223 | # html_use_opensearch = '' 224 | 225 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 226 | # html_file_suffix = None 227 | 228 | # Language to be used for generating the HTML full-text search index. 229 | # Sphinx supports the following languages: 230 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 231 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' 232 | # 233 | # html_search_language = 'en' 234 | 235 | # A dictionary with options for the search language support, empty by default. 236 | # 'ja' uses this config value. 237 | # 'zh' user can custom change `jieba` dictionary path. 238 | # 239 | # html_search_options = {'type': 'default'} 240 | 241 | # The name of a javascript file (relative to the configuration directory) that 242 | # implements a search results scorer. If empty, the default will be used. 243 | # 244 | # html_search_scorer = 'scorer.js' 245 | 246 | # Output file base name for HTML help builder. 247 | htmlhelp_basename = 'pypifdoc' 248 | 249 | # -- Options for LaTeX output --------------------------------------------- 250 | 251 | latex_elements = { 252 | # The paper size ('letterpaper' or 'a4paper'). 253 | # 254 | # 'papersize': 'letterpaper', 255 | 256 | # The font size ('10pt', '11pt' or '12pt'). 257 | # 258 | # 'pointsize': '10pt', 259 | 260 | # Additional stuff for the LaTeX preamble. 261 | # 262 | # 'preamble': '', 263 | 264 | # Latex figure (float) alignment 265 | # 266 | # 'figure_align': 'htbp', 267 | } 268 | 269 | # Grouping the document tree into LaTeX files. List of tuples 270 | # (source start file, target name, title, 271 | # author, documentclass [howto, manual, or own class]). 272 | latex_documents = [ 273 | (master_doc, 'pypif.tex', 'pypif Documentation', 274 | 'Kyle Michel, Max Hutchinson', 'manual'), 275 | ] 276 | 277 | # The name of an image file (relative to this directory) to place at the top of 278 | # the title page. 279 | # 280 | # latex_logo = None 281 | 282 | # For "manual" documents, if this is true, then toplevel headings are parts, 283 | # not chapters. 284 | # 285 | # latex_use_parts = False 286 | 287 | # If true, show page references after internal links. 288 | # 289 | # latex_show_pagerefs = False 290 | 291 | # If true, show URL addresses after external links. 292 | # 293 | # latex_show_urls = False 294 | 295 | # Documents to append as an appendix to all manuals. 296 | # 297 | # latex_appendices = [] 298 | 299 | # It false, will not define \strong, \code, itleref, \crossref ... but only 300 | # \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added 301 | # packages. 302 | # 303 | # latex_keep_old_macro_names = True 304 | 305 | # If false, no module index is generated. 306 | # 307 | # latex_domain_indices = True 308 | 309 | 310 | # -- Options for manual page output --------------------------------------- 311 | 312 | # One entry per manual page. List of tuples 313 | # (source start file, name, description, authors, manual section). 314 | man_pages = [ 315 | (master_doc, 'pypif', 'pypif Documentation', 316 | [author], 1) 317 | ] 318 | 319 | # If true, show URL addresses after external links. 320 | # 321 | # man_show_urls = False 322 | 323 | 324 | # -- Options for Texinfo output ------------------------------------------- 325 | 326 | # Grouping the document tree into Texinfo files. List of tuples 327 | # (source start file, target name, title, author, 328 | # dir menu entry, description, category) 329 | texinfo_documents = [ 330 | (master_doc, 'pypif', 'pypif Documentation', 331 | author, 'pypif', 'One line description of project.', 332 | 'Miscellaneous'), 333 | ] 334 | 335 | # Documents to append as an appendix to all manuals. 336 | # 337 | # texinfo_appendices = [] 338 | 339 | # If false, no module index is generated. 340 | # 341 | # texinfo_domain_indices = True 342 | 343 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 344 | # 345 | # texinfo_show_urls = 'footnote' 346 | 347 | # If true, do not generate a @detailmenu in the "Top" node's menu. 348 | # 349 | # texinfo_no_detailmenu = False 350 | 351 | 352 | # Example configuration for intersphinx: refer to the Python standard library. 353 | intersphinx_mapping = {'https://docs.python.org/': None} 354 | 355 | def skip(app, what, name, obj, skip, options): 356 | if name == "__init__": 357 | return False 358 | return skip 359 | 360 | def setup(app): 361 | app.connect("autodoc-skip-member", skip) 362 | -------------------------------------------------------------------------------- /docs/src/index.rst: -------------------------------------------------------------------------------- 1 | .. pypif documentation master file, created by 2 | sphinx-quickstart on Mon Jan 23 09:27:47 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | PyPIF documentation 7 | ================================= 8 | 9 | PyPIF is a package of tools to serialize and deserialize to and from the `PIF schema`__. 10 | This package provides python objects for each object in the PIF schema and methods 11 | for serialization and deserialization. 12 | 13 | __ http://citrineinformatics.github.io/pif-documentation/index.html 14 | 15 | PyPIF is a peer to the Java package JPIF__. 16 | 17 | __ https://github.com/CitrineInformatics/jpif 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` 25 | 26 | -------------------------------------------------------------------------------- /pypif/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '2.1.1' 2 | -------------------------------------------------------------------------------- /pypif/obj/__init__.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.common import * 2 | from pypif.obj.system import * 3 | -------------------------------------------------------------------------------- /pypif/obj/common/__init__.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.common.classification import Classification 2 | from pypif.obj.common.display_item import DisplayItem 3 | from pypif.obj.common.id import Id 4 | from pypif.obj.common.instrument import Instrument 5 | from pypif.obj.common.file_reference import FileReference 6 | from pypif.obj.common.license import License 7 | from pypif.obj.common.method import Method 8 | from pypif.obj.common.name import Name 9 | from pypif.obj.common.pages import Pages 10 | from pypif.obj.common.person import Person 11 | from pypif.obj.common.process_step import ProcessStep 12 | from pypif.obj.common.property import Property 13 | from pypif.obj.common.quantity import Quantity 14 | from pypif.obj.common.reference import Reference 15 | from pypif.obj.common.scalar import Scalar 16 | from pypif.obj.common.software import Software 17 | from pypif.obj.common.source import Source 18 | from pypif.obj.common.value import Value 19 | -------------------------------------------------------------------------------- /pypif/obj/common/classification.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.obj.common.pio import Pio 4 | 5 | 6 | class Classification(Pio): 7 | """ 8 | Information about a classification. 9 | """ 10 | 11 | def __init__(self, name=None, value=None, tags=None, **kwargs): 12 | """ 13 | Constructor. 14 | 15 | :param name: String with the name of the classification. 16 | :param value: String or number with the value of the classification. 17 | :param tags: List of strings or numbers that are tags for this object. 18 | :param kwargs: Dictionary of fields that are not supported. 19 | """ 20 | super(Classification, self).__init__(tags=tags, **kwargs) 21 | self._name = None 22 | self.name = name 23 | self._value = None 24 | self.value = value 25 | 26 | @property 27 | def name(self): 28 | return self._name 29 | 30 | @name.setter 31 | def name(self, name): 32 | self._validate_type('name', name, string_types) 33 | self._name = name 34 | 35 | @name.deleter 36 | def name(self): 37 | self._name = None 38 | 39 | @property 40 | def value(self): 41 | return self._value 42 | 43 | @value.setter 44 | def value(self, value): 45 | self._validate_list_type('value', value, string_types, numbers.Number) 46 | self._value = value 47 | 48 | @value.deleter 49 | def value(self): 50 | self._value = None 51 | -------------------------------------------------------------------------------- /pypif/obj/common/display_item.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class DisplayItem(Pio): 6 | """ 7 | Representation of a display item (table or figure) in a referenced work. 8 | """ 9 | 10 | def __init__(self, number=None, title=None, caption=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param number: String with the number of the item in the referenced work. 15 | :param title: Title of the item. 16 | :param caption: Caption associated with the item. 17 | :param tags: List of strings or numbers that are tags for this object. 18 | :param kwargs: Dictionary of fields that are not supported. 19 | """ 20 | super(DisplayItem, self).__init__(tags=tags, **kwargs) 21 | self._number = None 22 | self.number = number 23 | self._title = None 24 | self.title = title 25 | self._caption = None 26 | self.caption = caption 27 | 28 | @property 29 | def number(self): 30 | return self._number 31 | 32 | @number.setter 33 | def number(self, number): 34 | self._validate_type('number', number, string_types) 35 | self._number = number 36 | 37 | @number.deleter 38 | def number(self): 39 | self._number = None 40 | 41 | @property 42 | def title(self): 43 | return self._title 44 | 45 | @title.setter 46 | def title(self, title): 47 | self._validate_type('title', title, string_types) 48 | self._title = title 49 | 50 | @title.deleter 51 | def title(self): 52 | self._title = None 53 | 54 | @property 55 | def caption(self): 56 | return self._caption 57 | 58 | @caption.setter 59 | def caption(self, caption): 60 | self._validate_type('caption', caption, string_types) 61 | self._caption = caption 62 | 63 | @caption.deleter 64 | def caption(self): 65 | self._caption = None 66 | -------------------------------------------------------------------------------- /pypif/obj/common/file_reference.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class FileReference(Pio): 6 | """ 7 | Information about a file. 8 | """ 9 | 10 | def __init__(self, relative_path=None, url=None, mime_type=None, sha256=None, md5=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param relative_path: String with the relative path (from the location of this file) of the file. 15 | :param mime_type: String with the mime type of the file. 16 | :param sha256: String with the SHA-256 hash of the file. 17 | :param md5: String with the MD5 hash of the file. 18 | :param tags: List of strings or numbers that are tags for this object. 19 | :param kwargs: Dictionary of fields that are not supported. 20 | """ 21 | super(FileReference, self).__init__(tags=tags, **kwargs) 22 | self._relative_path = None 23 | self.relative_path = relative_path 24 | self._url = None 25 | self.url = url 26 | self._mime_type = None 27 | self.mime_type = mime_type 28 | self._sha256 = None 29 | self.sha256 = None 30 | self._md5 = None 31 | self.md5 = None 32 | 33 | @property 34 | def relative_path(self): 35 | return self._relative_path 36 | 37 | @relative_path.setter 38 | def relative_path(self, relative_path): 39 | self._validate_type('relative_path', relative_path, string_types) 40 | self._relative_path = relative_path 41 | 42 | @relative_path.deleter 43 | def relative_path(self): 44 | self._relative_path = None 45 | 46 | @property 47 | def url(self): 48 | return self._url 49 | 50 | @url.setter 51 | def url(self, url): 52 | self._validate_type('url', url, string_types) 53 | self._url = url 54 | 55 | @url.deleter 56 | def url(self): 57 | self._url = None 58 | 59 | @property 60 | def mime_type(self): 61 | return self._mime_type 62 | 63 | @mime_type.setter 64 | def mime_type(self, mime_type): 65 | self._validate_type('mime_type', mime_type, string_types) 66 | self._mime_type = mime_type 67 | 68 | @mime_type.deleter 69 | def mime_type(self): 70 | self._mime_type = None 71 | 72 | @property 73 | def sha256(self): 74 | return self._sha256 75 | 76 | @sha256.setter 77 | def sha256(self, sha256): 78 | self._validate_type('sha256', sha256, string_types) 79 | self._sha256 = sha256 80 | 81 | @sha256.deleter 82 | def sha256(self): 83 | self._sha256 = None 84 | 85 | @property 86 | def md5(self): 87 | return self._md5 88 | 89 | @md5.setter 90 | def md5(self, md5): 91 | self._validate_type('md5', md5, string_types) 92 | self._md5 = md5 93 | 94 | @md5.deleter 95 | def md5(self): 96 | self._md5 = None 97 | -------------------------------------------------------------------------------- /pypif/obj/common/id.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.obj.common.pio import Pio 4 | 5 | 6 | class Id(Pio): 7 | """ 8 | Information about a generic identifier. 9 | """ 10 | 11 | def __init__(self, name=None, value=None, tags=None, **kwargs): 12 | """ 13 | Constructor. 14 | 15 | :param name: String with the name of the identifier. 16 | :param value: String or number with the value of the identifier. 17 | :param tags: List of strings or numbers that are tags for this object. 18 | :param kwargs: Dictionary of fields that are not supported. 19 | """ 20 | super(Id, self).__init__(tags=tags, **kwargs) 21 | self._name = None 22 | self.name = name 23 | self._value = None 24 | self.value = value 25 | 26 | @property 27 | def name(self): 28 | return self._name 29 | 30 | @name.setter 31 | def name(self, name): 32 | self._validate_type('name', name, string_types) 33 | self._name = name 34 | 35 | @name.deleter 36 | def name(self): 37 | self._name = None 38 | 39 | @property 40 | def value(self): 41 | return self._value 42 | 43 | @value.setter 44 | def value(self, value): 45 | self._validate_list_type('value', value, string_types, numbers.Number) 46 | self._value = value 47 | 48 | @value.deleter 49 | def value(self): 50 | self._value = None 51 | -------------------------------------------------------------------------------- /pypif/obj/common/instrument.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class Instrument(Pio): 6 | """ 7 | Information about an instrument used to take a measurement. 8 | """ 9 | 10 | def __init__(self, name=None, model=None, producer=None, url=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param name: String with the name of the instrument. 15 | :param model: String with the model of the instrument. 16 | :param producer: String with the name of the producer of the instrument. 17 | :param url: URL to the instrument website. 18 | :param tags: List of strings or numbers that are tags for this object. 19 | :param kwargs: Dictionary of fields that are not supported. 20 | """ 21 | super(Instrument, self).__init__(tags=tags, **kwargs) 22 | self._name = None 23 | self.name = name 24 | self._model = None 25 | self.model = model 26 | self._producer = None 27 | self.producer = producer 28 | self._url = None 29 | self.url = url 30 | 31 | @property 32 | def name(self): 33 | return self._name 34 | 35 | @name.setter 36 | def name(self, name): 37 | self._validate_type('name', name, string_types) 38 | self._name = name 39 | 40 | @name.deleter 41 | def name(self): 42 | self._name = None 43 | 44 | @property 45 | def model(self): 46 | return self._model 47 | 48 | @model.setter 49 | def model(self, model): 50 | self._validate_type('model', model, string_types) 51 | self._model = model 52 | 53 | @model.deleter 54 | def model(self): 55 | self._model = None 56 | 57 | @property 58 | def producer(self): 59 | return self._producer 60 | 61 | @producer.setter 62 | def producer(self, producer): 63 | self._validate_type('producer', producer, string_types) 64 | self._producer = producer 65 | 66 | @producer.deleter 67 | def producer(self): 68 | self._producer = None 69 | 70 | @property 71 | def url(self): 72 | return self._url 73 | 74 | @url.setter 75 | def url(self, url): 76 | self._validate_type('url', url, string_types) 77 | self._url = url 78 | 79 | @url.deleter 80 | def url(self): 81 | self._url = None 82 | -------------------------------------------------------------------------------- /pypif/obj/common/license.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class License(Pio): 6 | """ 7 | Information about a license that applies to some item. 8 | """ 9 | 10 | def __init__(self, name=None, description=None, url=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param name: String with the name of the license. 15 | :param description: String with the description of the license. 16 | :param url: String with the URL to the license. 17 | :param tags: List of strings or numbers that are tags for this object. 18 | :param kwargs: Dictionary of fields that are not supported. 19 | """ 20 | super(License, self).__init__(tags=tags, **kwargs) 21 | self._name = None 22 | self.name = name 23 | self._description = None 24 | self.description = description 25 | self._url = None 26 | self.url = url 27 | 28 | @property 29 | def name(self): 30 | return self._name 31 | 32 | @name.setter 33 | def name(self, name): 34 | self._validate_type('name', name, string_types) 35 | self._name = name 36 | 37 | @name.deleter 38 | def name(self): 39 | self._name = None 40 | 41 | @property 42 | def description(self): 43 | return self._description 44 | 45 | @description.setter 46 | def description(self, description): 47 | self._validate_type('description', description, string_types) 48 | self._description = description 49 | 50 | @description.deleter 51 | def description(self): 52 | self._description = None 53 | 54 | @property 55 | def url(self): 56 | return self._url 57 | 58 | @url.setter 59 | def url(self, url): 60 | self._validate_type('url', url, string_types) 61 | self._url = url 62 | 63 | @url.deleter 64 | def url(self): 65 | self._url = None 66 | -------------------------------------------------------------------------------- /pypif/obj/common/method.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.instrument import Instrument 3 | from pypif.obj.common.pio import Pio 4 | from pypif.obj.common.software import Software 5 | 6 | 7 | class Method(Pio): 8 | """ 9 | Information about a method used in obtaining a property value. 10 | """ 11 | 12 | def __init__(self, name=None, instruments=None, software=None, tags=None, **kwargs): 13 | """ 14 | Constructor. 15 | 16 | :param name: String with the name of the method. 17 | :param instruments: List of dictionaries or :class:`.Instrument` objects used in the method. 18 | :param software: List of dictionaries or :class:`.Software` objects used in the method. 19 | :param kwargs: Dictionary of fields that are not supported. 20 | """ 21 | super(Method, self).__init__(tags=tags, **kwargs) 22 | self._name = None 23 | self.name = name 24 | self._instruments = None 25 | self.instruments = instruments 26 | self._software = None 27 | self.software = software 28 | 29 | @property 30 | def name(self): 31 | return self._name 32 | 33 | @name.setter 34 | def name(self, name): 35 | self._validate_type('name', name, string_types) 36 | self._name = name 37 | 38 | @property 39 | def instruments(self): 40 | return self._instruments 41 | 42 | @instruments.setter 43 | def instruments(self, instruments): 44 | self._validate_list_type('instruments', instruments, dict, Instrument) 45 | self._instruments = self._get_object(Instrument, instruments) 46 | 47 | @instruments.deleter 48 | def instruments(self): 49 | self._instruments = None 50 | 51 | @property 52 | def software(self): 53 | return self._software 54 | 55 | @software.setter 56 | def software(self, software): 57 | self._validate_list_type('software', software, dict, Software) 58 | self._software = self._get_object(Software, software) 59 | 60 | @software.deleter 61 | def software(self): 62 | self._software = None 63 | -------------------------------------------------------------------------------- /pypif/obj/common/name.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class Name(Pio): 6 | """ 7 | Representation of the first and last name of a person. 8 | """ 9 | 10 | def __init__(self, title=None, given=None, family=None, suffix=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param title: Title of the person (e.g. Prof. or Dr.) 15 | :param given: Given (first) name of a person. 16 | :param family: Family (last) name of a person. 17 | :param suffix: Suffix of the person (e.g. Jr. or Sr.) 18 | :param tags: List of strings or numbers that are tags for this object. 19 | :param kwargs: Dictionary of fields that are not supported. 20 | """ 21 | super(Name, self).__init__(tags=tags, **kwargs) 22 | self._title = None 23 | self.title = title 24 | self._given = None 25 | self.given = given 26 | self._family = None 27 | self.family = family 28 | self._suffix = None 29 | self.suffix = suffix 30 | 31 | @property 32 | def title(self): 33 | return self._title 34 | 35 | @title.setter 36 | def title(self, title): 37 | self._validate_type('title', title, string_types) 38 | self._title = title 39 | 40 | @title.deleter 41 | def title(self): 42 | self._title = None 43 | 44 | @property 45 | def given(self): 46 | return self._given 47 | 48 | @given.setter 49 | def given(self, given): 50 | self._validate_type('given', given, string_types) 51 | self._given = given 52 | 53 | @given.deleter 54 | def given(self): 55 | self._given = None 56 | 57 | @property 58 | def family(self): 59 | return self._family 60 | 61 | @family.setter 62 | def family(self, family): 63 | self._validate_type('family', family, string_types) 64 | self._family = family 65 | 66 | @family.deleter 67 | def family(self): 68 | self._family = None 69 | 70 | @property 71 | def suffix(self): 72 | return self._suffix 73 | 74 | @suffix.setter 75 | def suffix(self, suffix): 76 | self._validate_type('suffix', suffix, string_types) 77 | self._suffix = suffix 78 | 79 | @suffix.deleter 80 | def suffix(self): 81 | self._suffix = None 82 | -------------------------------------------------------------------------------- /pypif/obj/common/pages.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class Pages(Pio): 6 | """ 7 | Representation of the starting and ending pages of a reference. 8 | """ 9 | 10 | def __init__(self, start=None, end=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param start: String or integer with the starting page. 15 | :param end: String or integer with the ending page. 16 | :param tags: List of strings or numbers that are tags for this object. 17 | :param kwargs: Dictionary of fields that are not supported. 18 | """ 19 | super(Pages, self).__init__(tags=tags, **kwargs) 20 | self._start = None 21 | self.start = start 22 | self._end = None 23 | self.end = end 24 | 25 | @property 26 | def start(self): 27 | return self._start 28 | 29 | @start.setter 30 | def start(self, start): 31 | self._validate_type('start', start, string_types, int) 32 | self._start = start 33 | 34 | @start.deleter 35 | def start(self): 36 | self._start = None 37 | 38 | @property 39 | def end(self): 40 | return self._end 41 | 42 | @end.setter 43 | def end(self, end): 44 | self._validate_type('end', end, string_types, int) 45 | self._end = end 46 | 47 | @end.deleter 48 | def end(self): 49 | self._end = None 50 | -------------------------------------------------------------------------------- /pypif/obj/common/person.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.name import Name 3 | from pypif.obj.common.pio import Pio 4 | 5 | 6 | class Person(Pio): 7 | """ 8 | Information about a person. 9 | """ 10 | 11 | def __init__(self, name=None, email=None, url=None, orcid=None, tags=None, **kwargs): 12 | """ 13 | Constructor. 14 | 15 | :param name: :class: Dictionary or `.Name` object for the person. 16 | :param email: String with the email address of the person. 17 | :param url: String with the url for the person. 18 | :param orcid: String with the `ORCID ORCID`_ identifier of the person. 19 | :param tags: List of strings or numbers that are tags for this object. 20 | :param kwargs: Dictionary of fields that are not supported. 21 | """ 22 | super(Person, self).__init__(tags=tags, **kwargs) 23 | self._name = None 24 | self.name = name 25 | self._email = None 26 | self.email = email 27 | self._url = None 28 | self.url = url 29 | self._orcid = None 30 | self.orcid = orcid 31 | 32 | @property 33 | def name(self): 34 | return self._name 35 | 36 | @name.setter 37 | def name(self, name): 38 | self._validate_type('name', name, dict, Name, string_types) 39 | self._name = self._get_object(Name, name) 40 | 41 | @name.deleter 42 | def name(self): 43 | self._name = None 44 | 45 | @property 46 | def email(self): 47 | return self._email 48 | 49 | @email.setter 50 | def email(self, email): 51 | self._validate_type('email', email, string_types) 52 | self._email = email 53 | 54 | @email.deleter 55 | def email(self): 56 | self._email = None 57 | 58 | @property 59 | def url(self): 60 | return self._url 61 | 62 | @url.setter 63 | def url(self, url): 64 | self._validate_type('url', url, string_types) 65 | self._url = url 66 | 67 | @url.deleter 68 | def url(self): 69 | self._url = None 70 | 71 | @property 72 | def orcid(self): 73 | return self._orcid 74 | 75 | @orcid.setter 76 | def orcid(self, orcid): 77 | self._validate_type('orcid', orcid, string_types) 78 | self._orcid = orcid 79 | 80 | @orcid.deleter 81 | def orcid(self): 82 | self._orcid = None 83 | -------------------------------------------------------------------------------- /pypif/obj/common/pio.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.util.serializable import Serializable 4 | 5 | 6 | class Pio(Serializable): 7 | """ 8 | Base class for all physical information objects. 9 | """ 10 | 11 | def __init__(self, tags=None, **kwargs): 12 | """ 13 | Constructor. This is used to set an fields on a pio that do not have first level support. 14 | 15 | :param tags: List of strings or numbers that are tags for this object. 16 | :param kwargs: Dictionary of field names to values. 17 | """ 18 | self._tags = None 19 | self.tags = tags 20 | for i in kwargs.keys(): 21 | setattr(self, i, kwargs[i]) 22 | 23 | @property 24 | def tags(self): 25 | return self._tags 26 | 27 | @tags.setter 28 | def tags(self, tags): 29 | self._validate_list_type('tags', tags, string_types, numbers.Number) 30 | self._tags = tags 31 | 32 | @tags.deleter 33 | def tags(self): 34 | self._tags = None 35 | 36 | def _validate_type(self, name, obj, *args): 37 | """ 38 | Helper function that checks the input object type against each in a list of classes. This function 39 | also allows the input value to be equal to None. 40 | 41 | :param name: Name of the object. 42 | :param obj: Object to check the type of. 43 | :param args: List of classes. 44 | :raises TypeError: if the input object is not of any of the allowed types. 45 | """ 46 | if obj is None: 47 | return 48 | for arg in args: 49 | if isinstance(obj, arg): 50 | return 51 | raise TypeError(self.__class__.__name__ + '.' + name + ' is of type ' + type(obj).__name__ + 52 | '. Must be equal to None or one of the following types: ' + str(args)) 53 | 54 | def _validate_type_not_null(self, name, obj, *args): 55 | """ 56 | Helper function that checks the input object type against each in a list of classes. 57 | 58 | :param name: Name of the object. 59 | :param obj: Object to check the type of. 60 | :param args: List of classes. 61 | :raises TypeError: if the input object is not of any of the allowed types. 62 | """ 63 | for arg in args: 64 | if isinstance(obj, arg): 65 | return 66 | raise TypeError(self.__class__.__name__ + '.' + name + ' is of type ' + type(obj).__name__ + 67 | '. Must be one of the following types: ' + str(args)) 68 | 69 | def _validate_list_type(self, name, obj, *args): 70 | """ 71 | Helper function that checks the input object type against each in a list of classes, or if the input object 72 | is a list, each value that it contains against that list. 73 | 74 | :param name: Name of the object. 75 | :param obj: Object to check the type of. 76 | :param args: List of classes. 77 | :raises TypeError: if the input object is not of any of the allowed types. 78 | """ 79 | if obj is None: 80 | return 81 | if isinstance(obj, list): 82 | for i in obj: 83 | self._validate_type_not_null(name, i, *args) 84 | else: 85 | self._validate_type(name, obj, *args) 86 | 87 | def _validate_nested_list_type(self, name, obj, nested_level, *args): 88 | """ 89 | Helper function that checks the input object as a list then recursively until nested_level is 1. 90 | 91 | :param name: Name of the object. 92 | :param obj: Object to check the type of. 93 | :param nested_level: Integer with the current nested level. 94 | :param args: List of classes. 95 | :raises TypeError: if the input object is not of any of the allowed types. 96 | """ 97 | if nested_level <= 1: 98 | self._validate_list_type(name, obj, *args) 99 | else: 100 | if obj is None: 101 | return 102 | if not isinstance(obj, list): 103 | raise TypeError(self.__class__.__name__ + '.' + name + ' contains value of type ' + 104 | type(obj).__name__ + ' where a list is expected') 105 | for sub_obj in obj: 106 | self._validate_nested_list_type(name, sub_obj, nested_level - 1, *args) 107 | -------------------------------------------------------------------------------- /pypif/obj/common/process_step.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | from pypif.obj.common.value import Value 4 | from pypif.obj.common.software import Software 5 | from pypif.obj.common.instrument import Instrument 6 | 7 | 8 | class ProcessStep(Pio): 9 | """ 10 | Information about a single step in a processing pipeline. 11 | """ 12 | 13 | def __init__(self, name=None, details=None, instruments=None, software=None, tags=None, **kwargs): 14 | """ 15 | Constructor. 16 | 17 | :param name: String with the name of the process step. 18 | :param details: List of dictionaries or :class:`.Value` objects with the details of the step. 19 | :param instruments: List of dictionaries or :class:`.Instrument` objects. 20 | :param software: List of dictionaries or :class:`.Software` objects. 21 | :param tags: List of strings or numbers that are tags for this object. 22 | :param kwargs: Dictionary of fields that are not supported. 23 | """ 24 | super(ProcessStep, self).__init__(tags=tags, **kwargs) 25 | self._name = None 26 | self.name = name 27 | self._details = None 28 | self.details = details 29 | self._instruments = None 30 | self.instruments = instruments 31 | self._software = None 32 | self.software = software 33 | 34 | @property 35 | def name(self): 36 | return self._name 37 | 38 | @name.setter 39 | def name(self, name): 40 | self._validate_type('name', name, string_types) 41 | self._name = name 42 | 43 | @name.deleter 44 | def name(self): 45 | self._name = None 46 | 47 | @property 48 | def details(self): 49 | return self._details 50 | 51 | @details.setter 52 | def details(self, details): 53 | self._validate_list_type('details', details, dict, Value) 54 | self._details = self._get_object(Value, details) 55 | 56 | @details.deleter 57 | def details(self): 58 | self._details = None 59 | 60 | @property 61 | def instruments(self): 62 | return self._instruments 63 | 64 | @instruments.setter 65 | def instruments(self, instruments): 66 | self._validate_list_type('instruments', instruments, dict, Instrument) 67 | self._instruments = self._get_object(Instrument, instruments) 68 | 69 | @instruments.deleter 70 | def instruments(self): 71 | self._instruments = None 72 | 73 | @property 74 | def software(self): 75 | return self._software 76 | 77 | @software.setter 78 | def software(self, software): 79 | self._validate_list_type('software', software, dict, Software) 80 | self._software = self._get_object(Software, software) 81 | -------------------------------------------------------------------------------- /pypif/obj/common/property.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.method import Method 3 | from pypif.obj.common.rcl import Rcl 4 | from pypif.obj.common.value import Value 5 | from warnings import warn 6 | 7 | 8 | class Property(Value, Rcl): 9 | """ 10 | Class to store information about a property and conditions under which it exists. 11 | """ 12 | 13 | def __init__(self, name=None, scalars=None, vectors=None, matrices=None, files=None, units=None, conditions=None, 14 | methods=None, data_type=None, references=None, contacts=None, licenses=None, tags=None, **kwargs): 15 | """ 16 | Constructor. 17 | 18 | :param name: String with the name of the property. 19 | :param scalars: One or more dictionaries, strings, numbers, or :class:`.Scalar` objects. 20 | :param vectors: One or more lists of dictionaries, strings, numbers, or :class:`.Scalar` objects, 21 | each representing a vector. 22 | :param matrices: One of more lists of lists of dictionaries, strings, numbers, or :class:`.Scalar` objects, 23 | each representing a matrix with rows as the innermost lists. 24 | :param files: One of more dictionaries, strings, or :class:`.FileReference` objects. 25 | :param units: String with the units of the property. 26 | :param conditions: List of dictionaries or :class:`.Value` objects with the conditions at which the 27 | property exists. 28 | :param methods: List of dictionary or :class:`.Method` object describing the method used to get the property value. 29 | :param data_type: String containing "EXPERIMENTAL", "COMPUTATIONAL", "FIT", or "MACHINE_LEARNING" to set the 30 | broad category of data. 31 | :param references: List of dictionaries or :class:`.Reference` objects where information about the 32 | property is published. 33 | :param contacts: List of dictionaries, strings, or :class:`.Person` objects with people to contact for 34 | information about the property. 35 | :param licenses: List of dictionaries, strings, or :class:`.License` objects with licensing information 36 | for the property. 37 | :param tags: List of strings or numbers that are tags for this object. 38 | :param kwargs: Dictionary of fields that are not supported. 39 | """ 40 | # The order of the constructors is important here. The second constructor could overwrite values set during 41 | # the first if there is overlap. 42 | Value.__init__(self, name=name, scalars=scalars, vectors=vectors, matrices=matrices, files=files, 43 | units=units, tags=tags, **kwargs) 44 | self.references = references 45 | self.contacts = contacts 46 | self.licenses = licenses 47 | self._conditions = None 48 | self.conditions = conditions 49 | if 'method' in kwargs: 50 | self.methods = kwargs['method'] 51 | self._methods = None 52 | self.methods = methods 53 | self._data_type = None 54 | self.data_type = data_type 55 | 56 | 57 | 58 | @property 59 | def conditions(self): 60 | return self._conditions 61 | 62 | @conditions.setter 63 | def conditions(self, conditions): 64 | self._validate_list_type('conditions', conditions, dict, Value) 65 | self._conditions = self._get_object(Value, conditions) 66 | 67 | @conditions.deleter 68 | def conditions(self): 69 | self._conditions = None 70 | 71 | @property 72 | def method(self): 73 | warn("method has been deprecated in favor of methods") 74 | return self._methods 75 | 76 | @method.setter 77 | def method(self, method): 78 | warn("method has been deprecated in favor of methods") 79 | self.methods = method 80 | 81 | @method.deleter 82 | def method(self): 83 | warn("method has been deprecated in favor of methods") 84 | del self.methods 85 | 86 | @property 87 | def methods(self): 88 | return self._methods 89 | 90 | @methods.setter 91 | def methods(self, methods): 92 | self._validate_list_type('methods', methods, dict, Method) 93 | self._methods = self._get_object(Method, methods) 94 | 95 | @methods.deleter 96 | def methods(self): 97 | self._methods = None 98 | 99 | @property 100 | def data_type(self): 101 | return self._data_type 102 | 103 | @data_type.setter 104 | def data_type(self, data_type): 105 | self._validate_type('data_type', data_type, string_types) 106 | self._data_type = data_type 107 | 108 | @data_type.deleter 109 | def data_type(self): 110 | self._data_type = None 111 | -------------------------------------------------------------------------------- /pypif/obj/common/quantity.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.common.pio import Pio 2 | from pypif.obj.common.scalar import Scalar 3 | 4 | 5 | class Quantity(Pio): 6 | """ 7 | Information about the quantity of a system. 8 | """ 9 | 10 | def __init__(self, actual_mass_percent=None, actual_volume_percent=None, actual_number_percent=None, 11 | ideal_mass_percent=None, ideal_volume_percent=None, ideal_number_percent=None, tags=None, **kwargs): 12 | """ 13 | Constructor. 14 | 15 | :param actual_mass_percent: Dictionary or :class:`.Scalar` object with the actual percent of the total mass 16 | made up by this system. 17 | :param actual_volume_percent: Dictionary or :class:`.Scalar` object with the actual percent of the total 18 | volume made up by this system. 19 | :param actual_number_percent: Dictionary or :class:`.Scalar` object with the actual percent of the total 20 | numeric quantity made up by this system. 21 | :param ideal_mass_percent: Dictionary or :class:`.Scalar` object with the ideal percent of the total mass 22 | made up by this system. 23 | :param ideal_volume_percent: Dictionary or :class:`.Scalar` object with the ideal percent of the total 24 | volume made up by this system. 25 | :param ideal_number_percent: Dictionary or :class:`.Scalar` object with the ideal percent of the total 26 | numeric quantity made up by this system. 27 | :param tags: List of tags that apply to the quantity. 28 | :param kwargs: Dictionary of fields that are not supported. 29 | """ 30 | super(Quantity, self).__init__(tags=tags, **kwargs) 31 | self._actual_mass_percent = None 32 | self.actual_mass_percent = actual_mass_percent 33 | self._actual_volume_percent = None 34 | self.actual_volume_percent = actual_volume_percent 35 | self._actual_number_percent = None 36 | self.actual_number_percent = actual_number_percent 37 | self._ideal_mass_percent = None 38 | self.ideal_mass_percent = ideal_mass_percent 39 | self._ideal_volume_percent = None 40 | self.ideal_volume_percent = ideal_volume_percent 41 | self._ideal_number_percent = None 42 | self.ideal_number_percent = ideal_number_percent 43 | 44 | @property 45 | def actual_mass_percent(self): 46 | return self._actual_mass_percent 47 | 48 | @actual_mass_percent.setter 49 | def actual_mass_percent(self, actual_mass_percent): 50 | self._validate_type('actual_mass_percent', actual_mass_percent, dict, Scalar) 51 | self._actual_mass_percent = self._get_object(Scalar, actual_mass_percent) 52 | 53 | @actual_mass_percent.deleter 54 | def actual_mass_percent(self): 55 | self._actual_mass_percent = None 56 | 57 | @property 58 | def actual_volume_percent(self): 59 | return self._actual_volume_percent 60 | 61 | @actual_volume_percent.setter 62 | def actual_volume_percent(self, actual_volume_percent): 63 | self._validate_type('actual_volume_percent', actual_volume_percent, dict, Scalar) 64 | self._actual_volume_percent = self._get_object(Scalar, actual_volume_percent) 65 | 66 | @actual_volume_percent.deleter 67 | def actual_volume_percent(self): 68 | self._actual_volume_percent = None 69 | 70 | @property 71 | def actual_number_percent(self): 72 | return self._actual_number_percent 73 | 74 | @actual_number_percent.setter 75 | def actual_number_percent(self, actual_number_percent): 76 | self._validate_type('actual_number_percent', actual_number_percent, dict, Scalar) 77 | self._actual_number_percent = self._get_object(Scalar, actual_number_percent) 78 | 79 | @actual_number_percent.deleter 80 | def actual_number_percent(self): 81 | self._actual_number_percent = None 82 | 83 | @property 84 | def ideal_mass_percent(self): 85 | return self._ideal_mass_percent 86 | 87 | @ideal_mass_percent.setter 88 | def ideal_mass_percent(self, ideal_mass_percent): 89 | self._validate_type('ideal_mass_percent', ideal_mass_percent, dict, Scalar) 90 | self._ideal_mass_percent = self._get_object(Scalar, ideal_mass_percent) 91 | 92 | @ideal_mass_percent.deleter 93 | def ideal_mass_percent(self): 94 | self._ideal_mass_percent = None 95 | 96 | @property 97 | def ideal_volume_percent(self): 98 | return self._ideal_volume_percent 99 | 100 | @ideal_volume_percent.setter 101 | def ideal_volume_percent(self, ideal_volume_percent): 102 | self._validate_type('ideal_volume_percent', ideal_volume_percent, dict, Scalar) 103 | self._ideal_volume_percent = self._get_object(Scalar, ideal_volume_percent) 104 | 105 | @ideal_volume_percent.deleter 106 | def ideal_volume_percent(self): 107 | self._ideal_volume_percent = None 108 | 109 | @property 110 | def ideal_number_percent(self): 111 | return self._ideal_number_percent 112 | 113 | @ideal_number_percent.setter 114 | def ideal_number_percent(self, ideal_number_percent): 115 | self._validate_type('ideal_number_percent', ideal_number_percent, dict, Scalar) 116 | self._ideal_number_percent = self._get_object(Scalar, ideal_number_percent) 117 | 118 | @ideal_number_percent.deleter 119 | def ideal_number_percent(self): 120 | self._ideal_number_percent = None 121 | -------------------------------------------------------------------------------- /pypif/obj/common/rcl.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.license import License 3 | from pypif.obj.common.person import Person 4 | from pypif.obj.common.pio import Pio 5 | from pypif.obj.common.reference import Reference 6 | 7 | 8 | class Rcl(Pio): 9 | """ 10 | Base class for any objects that contain reference, contact, and license information. 11 | """ 12 | 13 | def __init__(self, references=None, contacts=None, licenses=None, tags=None, **kwargs): 14 | """ 15 | Constructor. 16 | 17 | :param references: List of dictionaries or :class:`.Reference` objects where information about this 18 | item is published. 19 | :param contacts: List of dictionaries, strings, or :class:`.Person` objects with people that can be 20 | contacted for information about this item. 21 | :param licenses: List of dictionaries, strings, or :class:`.License` objects with licensing information 22 | for this item. 23 | :param tags: List of strings or numbers that are tags for this object. 24 | :param kwargs: Dictionary of fields that are not supported. 25 | """ 26 | super(Rcl, self).__init__(tags=tags, **kwargs) 27 | self._references = None 28 | self.references = references 29 | self._contacts = None 30 | self.contacts = contacts 31 | self._licenses = None 32 | self.licenses = licenses 33 | 34 | @property 35 | def references(self): 36 | return self._references 37 | 38 | @references.setter 39 | def references(self, references): 40 | self._validate_list_type('references', references, dict, Reference) 41 | self._references = self._get_object(Reference, references) 42 | 43 | @references.deleter 44 | def references(self): 45 | self._references = None 46 | 47 | @property 48 | def contacts(self): 49 | return self._contacts 50 | 51 | @contacts.setter 52 | def contacts(self, contacts): 53 | self._validate_list_type('contacts', contacts, dict, string_types, Person) 54 | self._contacts = self._get_object(Person, contacts) 55 | 56 | @contacts.deleter 57 | def contacts(self): 58 | self._contacts = None 59 | 60 | @property 61 | def licenses(self): 62 | return self._licenses 63 | 64 | @licenses.setter 65 | def licenses(self, licenses): 66 | self._validate_list_type('licenses', licenses, dict, string_types, License) 67 | self._licenses = self._get_object(License, licenses) 68 | 69 | @licenses.deleter 70 | def licenses(self): 71 | self._licenses = None 72 | -------------------------------------------------------------------------------- /pypif/obj/common/reference.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.display_item import DisplayItem 3 | from pypif.obj.common.name import Name 4 | from pypif.obj.common.pages import Pages 5 | from pypif.obj.common.pio import Pio 6 | 7 | 8 | class Reference(Pio): 9 | """ 10 | Information about a referenced publication. 11 | """ 12 | 13 | def __init__(self, doi=None, isbn=None, issn=None, url=None, title=None, publisher=None, journal=None, volume=None, 14 | issue=None, year=None, figure=None, table=None, pages=None, authors=None, editors=None, 15 | affiliations=None, acknowledgements=None, references=None, tags=None, **kwargs): 16 | """ 17 | Constructor. 18 | 19 | :param doi: String with DOI of the published work 20 | :param isbn: String with ISBN of the published work 21 | :param issn: String with ISSN of the published work 22 | :param url: String with URL to the published work 23 | :param title: String with title of the published work. 24 | :param publisher: String with publisher of the work. 25 | :param journal: String with the journal in which the work was published. 26 | :param volume: String with the volume in which the work was published. 27 | :param issue: String with the issue in which the work was published. 28 | :param year: String with the year in which the work was published. 29 | :param figure: Dictionary or :class:`.DisplayItem` object with the figure to reference. 30 | :param table: Dictionary or :class:`.DisplayItem` object with the table to reference. 31 | :param pages: String, integer, dictionary, or :class:`.Pages` object with the starting and ending pages for 32 | the published work. 33 | :param authors: List of strings, dictionaries, or :class:`.Name` objects with information about the authors. 34 | :param editors: List of strings, dictionaries, or :class:`.Name` objects with information about the editors. 35 | :param affiliations: List of strings with affiliations. 36 | :param acknowledgements: List of strings with acknowledgements. 37 | :param references: List of dictionaries or :class:`.Reference` objects with works cited by this published work. 38 | :param tags: List of strings or numbers that are tags for this object. 39 | :param kwargs: Dictionary of fields that are not supported. 40 | """ 41 | super(Reference, self).__init__(tags=tags, **kwargs) 42 | self._doi = None 43 | self.doi = doi 44 | self._isbn = None 45 | self.isbn = isbn 46 | self._issn = None 47 | self.issn = issn 48 | self._url = None 49 | self.url = url 50 | self._title = None 51 | self.title = title 52 | self._publisher = None 53 | self.publisher = publisher 54 | self._journal = None 55 | self.journal = journal 56 | self._volume = None 57 | self.volume = volume 58 | self._issue = None 59 | self.issue = issue 60 | self._year = None 61 | self.year = year 62 | self._figure = None 63 | self.figure = figure 64 | self._table = None 65 | self.table = table 66 | self._pages = None 67 | self.pages = pages 68 | self._authors = None 69 | self.authors = authors 70 | self._editors = None 71 | self.editors = editors 72 | self._affiliations = None 73 | self.affiliations = affiliations 74 | self._acknowledgements = None 75 | self.acknowledgements = acknowledgements 76 | self._references = None 77 | self.references = references 78 | 79 | @property 80 | def doi(self): 81 | return self._doi 82 | 83 | @doi.setter 84 | def doi(self, doi): 85 | self._validate_type('doi', doi, string_types) 86 | self._doi = doi 87 | 88 | @doi.deleter 89 | def doi(self): 90 | self._doi = None 91 | 92 | @property 93 | def isbn(self): 94 | return self._isbn 95 | 96 | @isbn.setter 97 | def isbn(self, isbn): 98 | self._validate_type('isbn', isbn, string_types) 99 | self._isbn = isbn 100 | 101 | @isbn.deleter 102 | def isbn(self): 103 | self._isbn = None 104 | 105 | @property 106 | def issn(self): 107 | return self._issn 108 | 109 | @issn.setter 110 | def issn(self, issn): 111 | self._validate_type('issn', issn, string_types) 112 | self._issn = issn 113 | 114 | @issn.deleter 115 | def issn(self): 116 | self._issn = None 117 | 118 | @property 119 | def url(self): 120 | return self._url 121 | 122 | @url.setter 123 | def url(self, url): 124 | self._validate_type('url', url, string_types) 125 | self._url = url 126 | 127 | @url.deleter 128 | def url(self): 129 | self._url = None 130 | 131 | @property 132 | def title(self): 133 | return self._title 134 | 135 | @title.setter 136 | def title(self, title): 137 | self._validate_type('title', title, string_types) 138 | self._title = title 139 | 140 | @title.deleter 141 | def title(self): 142 | self._title = None 143 | 144 | @property 145 | def publisher(self): 146 | return self._publisher 147 | 148 | @publisher.setter 149 | def publisher(self, publisher): 150 | self._validate_type('publisher', publisher, string_types) 151 | self._publisher = publisher 152 | 153 | @publisher.deleter 154 | def publisher(self): 155 | self._publisher = None 156 | 157 | @property 158 | def journal(self): 159 | return self._journal 160 | 161 | @journal.setter 162 | def journal(self, journal): 163 | self._validate_type('journal', journal, string_types) 164 | self._journal = journal 165 | 166 | @journal.deleter 167 | def journal(self): 168 | self._journal = None 169 | 170 | @property 171 | def volume(self): 172 | return self._volume 173 | 174 | @volume.setter 175 | def volume(self, volume): 176 | self._validate_type('volume', volume, string_types) 177 | self._volume = volume 178 | 179 | @volume.deleter 180 | def volume(self): 181 | self._volume = None 182 | 183 | @property 184 | def issue(self): 185 | return self._issue 186 | 187 | @issue.setter 188 | def issue(self, issue): 189 | self._validate_type('issue', issue, string_types) 190 | self._issue = issue 191 | 192 | @issue.deleter 193 | def issue(self): 194 | self._issue = None 195 | 196 | @property 197 | def year(self): 198 | return self._year 199 | 200 | @year.setter 201 | def year(self, year): 202 | self._validate_type('year', year, string_types) 203 | self._year = year 204 | 205 | @year.deleter 206 | def year(self): 207 | self._year = None 208 | 209 | @property 210 | def figure(self): 211 | return self._figure 212 | 213 | @figure.setter 214 | def figure(self, figure): 215 | self._validate_type('figure', figure, dict, DisplayItem) 216 | self._figure = self._get_object(DisplayItem, figure) 217 | 218 | @figure.deleter 219 | def figure(self): 220 | self._figure = None 221 | 222 | @property 223 | def table(self): 224 | return self._table 225 | 226 | @table.setter 227 | def table(self, table): 228 | self._validate_type('table', table, dict, DisplayItem) 229 | self._table = self._get_object(DisplayItem, table) 230 | 231 | @table.deleter 232 | def table(self): 233 | self._table = None 234 | 235 | @property 236 | def pages(self): 237 | return self._pages 238 | 239 | @pages.setter 240 | def pages(self, pages): 241 | self._validate_type('pages', pages, string_types, int, dict, Pages) 242 | self._pages = self._get_object(Pages, pages) 243 | 244 | @pages.deleter 245 | def pages(self): 246 | self._pages = None 247 | 248 | @property 249 | def authors(self): 250 | return self._authors 251 | 252 | @authors.setter 253 | def authors(self, authors): 254 | self._validate_list_type('authors', authors, string_types, dict, Name) 255 | self._authors = self._get_object(Name, authors) 256 | 257 | @authors.deleter 258 | def authors(self): 259 | self._authors = None 260 | 261 | @property 262 | def editors(self): 263 | return self._editors 264 | 265 | @editors.setter 266 | def editors(self, editors): 267 | self._validate_list_type('editors', editors, string_types, dict, Name) 268 | self._editors = self._get_object(Name, editors) 269 | 270 | @editors.deleter 271 | def editors(self): 272 | self._editors = None 273 | 274 | @property 275 | def affiliations(self): 276 | return self._affiliations 277 | 278 | @affiliations.setter 279 | def affiliations(self, affiliations): 280 | self._validate_list_type('affiliations', affiliations, string_types) 281 | self._affiliations = affiliations 282 | 283 | @affiliations.deleter 284 | def affiliations(self): 285 | self._affiliations = None 286 | 287 | @property 288 | def acknowledgements(self): 289 | return self._acknowledgements 290 | 291 | @acknowledgements.setter 292 | def acknowledgements(self, acknowledgements): 293 | self._validate_list_type('acknowledgements', acknowledgements, string_types) 294 | self._acknowledgements = acknowledgements 295 | 296 | @acknowledgements.deleter 297 | def acknowledgements(self): 298 | self._acknowledgements = None 299 | 300 | @property 301 | def references(self): 302 | return self._references 303 | 304 | @references.setter 305 | def references(self, references): 306 | self._validate_list_type('references', references, dict, Reference) 307 | self._references = self._get_object(Reference, references) 308 | -------------------------------------------------------------------------------- /pypif/obj/common/scalar.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.obj.common.pio import Pio 4 | 5 | 6 | class Scalar(Pio): 7 | """ 8 | Representation of a single scalar value that could represent an absolute point, an uncertain point, 9 | a range of values, a minimum, or a maximum. 10 | """ 11 | 12 | def __init__(self, value=None, minimum=None, inclusive_minimum=None, maximum=None, inclusive_maximum=None, 13 | uncertainty=None, approximate=None, tags=None, **kwargs): 14 | """ 15 | Constructor. 16 | 17 | :param value: String or number with the value for the point. 18 | :param minimum: String or number with the minimum value for the point. 19 | :apram inclusive_minimum: Boolean with whether the minimum is inclusive. 20 | :param maximum: String or number with the maximum value for the point. 21 | :param inclusive_maximum: Boolean with whether the maximum is inclusive. 22 | :param uncertainty: String or number with the isotropic uncertainty for the point. 23 | :param approximate: Boolean with whether the value is approximate. 24 | :param tags: List of strings or numbers that are tags for this object. 25 | :param kwargs: Dictionary of fields that are not supported. 26 | """ 27 | super(Scalar, self).__init__(tags=tags, **kwargs) 28 | self._value = None 29 | self.value = value 30 | self._minimum = None 31 | self.minimum = minimum 32 | self._inclusive_minimum = None 33 | self.inclusive_minimum = inclusive_minimum 34 | self._maximum = None 35 | self.maximum = maximum 36 | self._inclusive_maximum = None 37 | self.inclusive_maximum = inclusive_maximum 38 | self._uncertainty = None 39 | self.uncertainty = uncertainty 40 | self._approximate = None 41 | self.approximate = approximate 42 | 43 | @property 44 | def value(self): 45 | return self._value 46 | 47 | @value.setter 48 | def value(self, value): 49 | self._validate_type('value', value, string_types, numbers.Number) 50 | self._value = value 51 | 52 | @value.deleter 53 | def value(self): 54 | self._value = None 55 | 56 | @property 57 | def minimum(self): 58 | return self._minimum 59 | 60 | @minimum.setter 61 | def minimum(self, minimum): 62 | self._validate_type('minimum', minimum, string_types, numbers.Number) 63 | self._minimum = minimum 64 | 65 | @minimum.deleter 66 | def minimum(self): 67 | self._minimum = None 68 | 69 | @property 70 | def inclusive_minimum(self): 71 | return self._inclusive_minimum 72 | 73 | @inclusive_minimum.setter 74 | def inclusive_minimum(self, inclusive_minimum): 75 | self._validate_type('inclusive_minimum', inclusive_minimum, bool) 76 | self._inclusive_minimum = inclusive_minimum 77 | 78 | @inclusive_minimum.deleter 79 | def inclusive_minimum(self): 80 | self._inclusive_minimum = None 81 | 82 | @property 83 | def maximum(self): 84 | return self._maximum 85 | 86 | @maximum.setter 87 | def maximum(self, maximum): 88 | self._validate_type('maximum', maximum, string_types, numbers.Number) 89 | self._maximum = maximum 90 | 91 | @maximum.deleter 92 | def maximum(self): 93 | self._maximum = None 94 | 95 | @property 96 | def inclusive_maximum(self): 97 | return self._inclusive_maximum 98 | 99 | @inclusive_maximum.setter 100 | def inclusive_maximum(self, inclusive_maximum): 101 | self._validate_type('inclusive_maximum', inclusive_maximum, bool) 102 | self._inclusive_maximum = inclusive_maximum 103 | 104 | @inclusive_maximum.deleter 105 | def inclusive_maximum(self): 106 | self._inclusive_maximum = None 107 | 108 | @property 109 | def uncertainty(self): 110 | return self._uncertainty 111 | 112 | @uncertainty.setter 113 | def uncertainty(self, uncertainty): 114 | self._validate_type('uncertainty', uncertainty, string_types, numbers.Number) 115 | self._uncertainty = uncertainty 116 | 117 | @uncertainty.deleter 118 | def uncertainty(self): 119 | self._uncertainty = None 120 | 121 | @property 122 | def approximate(self): 123 | return self._approximate 124 | 125 | @approximate.setter 126 | def approximate(self, approximate): 127 | self._validate_type('approximate', approximate, bool) 128 | self._approximate = approximate 129 | 130 | @approximate.deleter 131 | def approximate(self): 132 | self._approximate = None 133 | -------------------------------------------------------------------------------- /pypif/obj/common/software.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class Software(Pio): 6 | """ 7 | Information about a software application. 8 | """ 9 | 10 | def __init__(self, name=None, version=None, producer=None, url=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param name: String with the name of the software. 15 | :param version: String with the version of the software. 16 | :param producer: String with the name of the producer of the software. 17 | :param url: URL to the software website. 18 | :param tags: List of strings or numbers that are tags for this object. 19 | :param kwargs: Dictionary of fields that are not supported. 20 | """ 21 | super(Software, self).__init__(tags=tags, **kwargs) 22 | self._name = None 23 | self.name = name 24 | self._version = None 25 | self.version = version 26 | self._producer = None 27 | self.producer = producer 28 | self._url = None 29 | self.url = url 30 | 31 | @property 32 | def name(self): 33 | return self._name 34 | 35 | @name.setter 36 | def name(self, name): 37 | self._validate_type('name', name, string_types) 38 | self._name = name 39 | 40 | @name.deleter 41 | def name(self): 42 | self._name = None 43 | 44 | @property 45 | def version(self): 46 | return self._version 47 | 48 | @version.setter 49 | def version(self, version): 50 | self._validate_type('version', version, string_types) 51 | self._version = version 52 | 53 | @version.deleter 54 | def version(self): 55 | self._version = None 56 | 57 | @property 58 | def producer(self): 59 | return self._producer 60 | 61 | @producer.setter 62 | def producer(self, producer): 63 | self._validate_type('producer', producer, string_types) 64 | self._producer = producer 65 | 66 | @producer.deleter 67 | def producer(self): 68 | self._producer = None 69 | 70 | @property 71 | def url(self): 72 | return self._url 73 | 74 | @url.setter 75 | def url(self, url): 76 | self._validate_type('url', url, string_types) 77 | self._url = url 78 | 79 | @url.deleter 80 | def url(self): 81 | self._url = None 82 | -------------------------------------------------------------------------------- /pypif/obj/common/source.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.common.pio import Pio 3 | 4 | 5 | class Source(Pio): 6 | """ 7 | Information about the source of a system. 8 | """ 9 | 10 | def __init__(self, producer=None, url=None, tags=None, **kwargs): 11 | """ 12 | Constructor. 13 | 14 | :param producer: String with the name of the producer. 15 | :param url: String with the URL to the source of the system. 16 | :param tags: List of strings or numbers that are tags for this object. 17 | :param kwargs: Dictionary of fields that are not supported. 18 | """ 19 | super(Source, self).__init__(tags=tags, **kwargs) 20 | self._producer = None 21 | self.producer = producer 22 | self._url = None 23 | self.url = url 24 | 25 | @property 26 | def producer(self): 27 | return self._producer 28 | 29 | @producer.setter 30 | def producer(self, producer): 31 | self._validate_type('producer', producer, string_types) 32 | self._producer = producer 33 | 34 | @producer.deleter 35 | def producer(self): 36 | self._producer = None 37 | 38 | @property 39 | def url(self): 40 | return self._url 41 | 42 | @url.setter 43 | def url(self, url): 44 | self._validate_type('url', url, string_types) 45 | self._url = url 46 | 47 | @url.deleter 48 | def url(self): 49 | self._url = None 50 | -------------------------------------------------------------------------------- /pypif/obj/common/tests/test_file_reference.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.common.file_reference import FileReference 2 | from pypif import pif 3 | 4 | def test_round_robin(): 5 | url = "https://citrination.com/datasets/1160/version/3/file/308882" 6 | path = "/tmp/foo.bar" 7 | fr = FileReference(url=url, relative_path=path) 8 | assert fr.relative_path == path, "Python object couldn't store relative path" 9 | assert fr.url == url, "Python object couldn't store URL" 10 | round_robin = pif.loads(pif.dumps(fr), class_=FileReference) 11 | assert round_robin.relative_path == path, "Relative path didn't survive json round robin" 12 | assert round_robin.url == url, "URL dind't survive json round robin" 13 | -------------------------------------------------------------------------------- /pypif/obj/common/tests/test_value.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.common.value import Value 2 | from pypif import pif 3 | import pytest 4 | 5 | 6 | def test_basic(): 7 | """Test that constructor arguments are saved""" 8 | foo = Value(name="foo", units="eV", tags=["tag1", "tag2"]) 9 | assert foo.name == "foo" 10 | assert foo.units == "eV" 11 | assert len(foo.tags) == 2 12 | assert "tag1" in foo.tags 13 | assert "tag2" in foo.tags 14 | 15 | 16 | def test_round_robin(): 17 | foo = Value(name="foo", units="eV") 18 | assert foo.name == "foo", "Value object couldn't store name" 19 | assert foo.units == "eV", "Value object couldn't store units" 20 | round_robin = pif.loads(pif.dumps(foo), class_=Value) 21 | assert round_robin.name == "foo", "Name didn't survive json round robin" 22 | assert round_robin.units == "eV", "Units didn't survive json round robin" 23 | 24 | 25 | @pytest.mark.xfail 26 | def test_convert_scalar(): 27 | """Test that scalars are made rigid""" 28 | foo = Value(scalars=1.2) 29 | assert foo.scalars[0].value == 1.2 30 | 31 | 32 | @pytest.mark.xfail 33 | def test_convert_setter(): 34 | """Test that scalars are made rigid""" 35 | foo = Value() 36 | foo.scalars = 1.2 37 | assert foo.scalars[0].value == 1.2 38 | 39 | 40 | @pytest.mark.xfail 41 | def test_convert_vector(): 42 | """Test that vectors are made rigid""" 43 | foo = Value(vectors=[1.2, 1.3]) 44 | assert foo.vectors[0][1].value == 1.3 45 | 46 | 47 | @pytest.mark.xfail 48 | def test_convert_matrix(): 49 | """Test that matrices are made rigid""" 50 | foo = Value(matrices=[[1.0, 2.0], [-2.0, 1.0]]) 51 | assert foo.matrices[0][0][1].value == 2.0 52 | assert foo.matrices[0][1][0].value == -2.0 53 | -------------------------------------------------------------------------------- /pypif/obj/common/value.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.obj.common.pio import Pio 4 | from pypif.obj.common.scalar import Scalar 5 | from pypif.obj.common.file_reference import FileReference 6 | 7 | 8 | class Value(Pio): 9 | """ 10 | Information about a scalar, vector, or matrix, or a list of one of those. 11 | """ 12 | 13 | def __init__(self, name=None, scalars=None, vectors=None, matrices=None, files=None, 14 | units=None, tags=None, **kwargs): 15 | """ 16 | Constructor. 17 | 18 | :param name: String with the name of the value. 19 | :param scalars: One or more dictionaries, strings, numbers, or :class:`.Scalar` objects. 20 | :param vectors: One or more lists of dictionaries, strings, numbers, or :class:`.Scalar` objects, 21 | each representing a vector. 22 | :param matrices: One of more lists of lists of dictionaries, strings, numbers, or :class:`.Scalar` objects, 23 | each representing a matrix with rows as the innermost lists. 24 | :param files: One of more dictionaries, strings, or :class:`.FileReference` objects. 25 | :param units: String with the units of the value. 26 | :param tags: List of strings or numbers that are tags for this object. 27 | :param kwargs: Dictionary of fields that are not supported. 28 | """ 29 | super(Value, self).__init__(tags=tags, **kwargs) 30 | self._name = None 31 | self.name = name 32 | 33 | self._files = None 34 | self.files = files 35 | 36 | self._scalars = None 37 | if scalars is not None: 38 | self.scalars = scalars 39 | 40 | self._vectors = None 41 | if vectors is not None: 42 | self.vectors = vectors 43 | 44 | self._matrices = None 45 | if matrices is not None: 46 | self.matrices = matrices 47 | 48 | self._units = None 49 | self.units = units 50 | 51 | @property 52 | def name(self): 53 | return self._name 54 | 55 | @name.setter 56 | def name(self, name): 57 | self._validate_type('name', name, string_types) 58 | self._name = name 59 | 60 | @name.deleter 61 | def name(self): 62 | self._name = None 63 | 64 | @property 65 | def scalars(self): 66 | return self._scalars 67 | 68 | @scalars.setter 69 | def scalars(self, scalars): 70 | self._validate_list_type('scalars', scalars, dict, string_types, numbers.Number, Scalar) 71 | self._scalars = self._get_object(Scalar, scalars) 72 | 73 | @scalars.deleter 74 | def scalars(self): 75 | self._scalars = None 76 | 77 | @property 78 | def vectors(self): 79 | return self._vectors 80 | 81 | @vectors.setter 82 | def vectors(self, vectors): 83 | self._validate_nested_list_type('vectors', vectors, 2, dict, string_types, numbers.Number, Scalar) 84 | self._vectors = self._get_object(Scalar, vectors) 85 | 86 | @vectors.deleter 87 | def vectors(self): 88 | self._vectors = None 89 | 90 | @property 91 | def matrices(self): 92 | return self._matrices 93 | 94 | @matrices.setter 95 | def matrices(self, matrices): 96 | self._validate_nested_list_type('matrices', matrices, 3, dict, string_types, numbers.Number, Scalar) 97 | self._matrices = self._get_object(Scalar, matrices) 98 | 99 | @matrices.deleter 100 | def matrices(self): 101 | self._matrices = None 102 | 103 | @property 104 | def units(self): 105 | return self._units 106 | 107 | @units.setter 108 | def units(self, units): 109 | self._validate_type('units', units, string_types) 110 | self._units = units 111 | 112 | @units.deleter 113 | def units(self): 114 | self._units = None 115 | 116 | @property 117 | def files(self): 118 | return self._files 119 | 120 | @files.setter 121 | def files(self, files): 122 | self._validate_list_type('files', files, dict, FileReference) 123 | self._files = self._get_object(FileReference, files) 124 | 125 | @files.deleter 126 | def files(self): 127 | self._files = None 128 | -------------------------------------------------------------------------------- /pypif/obj/system/__init__.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.system.chemical import * 2 | from pypif.obj.system.system import System 3 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/__init__.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.system.chemical.alloy import * 2 | from pypif.obj.system.chemical.common import * 3 | from pypif.obj.system.chemical.chemical_system import ChemicalSystem 4 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/alloy/__init__.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.system.chemical.alloy.alloy import Alloy 2 | from pypif.obj.system.chemical.alloy.alloy_phase import AlloyPhase 3 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/alloy/alloy.py: -------------------------------------------------------------------------------- 1 | from warnings import warn 2 | from pypif.obj.system.chemical.chemical_system import ChemicalSystem 3 | 4 | 5 | class Alloy(ChemicalSystem): 6 | """ 7 | Information about an alloy. 8 | """ 9 | 10 | def __init__(self, uid=None, names=None, ids=None, source=None, quantity=None, chemical_formula=None, 11 | composition=None, properties=None, preparation=None, sub_systems=None, phases=None, 12 | references=None, contacts=None, licenses=None, tags=None, **kwargs): 13 | """ 14 | Constructor. 15 | 16 | :param uid: String with the permanent ID for this record. 17 | :param names: List of strings with common names of the alloy. 18 | :param ids: List of dictionaries, strings, numbers, or :class:`.Id` objects that identify the alloy. 19 | :param source: Dictionary, string, or :class:`.Source` object with the source of the alloy. 20 | :param quantity: Dictionary or :class:`.Quantity` object with the quantity of the alloy. 21 | :param chemical_formula: String with the chemical formula. 22 | :param composition: List of dictionaries or :class:`.Composition` objects that describe the composition of 23 | the alloy. 24 | :param properties: List of dictionaries or :class:`.Property` objects with properties of the alloy. 25 | :param preparation: List of dictionaries or :class:`.ProcessStep` objects with the preparation 26 | information of the alloy. 27 | :param sub_systems: List of dictionaries or :class:`.System` objects with the subsystems of the alloy. 28 | :param phases: List of dictionaries or :class:`.AlloyPhase` objects with the phases of the alloy. 29 | :param references: List of dictionaries or :class:`.Reference` objects where information about the alloy 30 | is published. 31 | :param contacts: List of dictionaries, strings, or :class:`.Person` objects with people to contact for 32 | information about the alloy. 33 | :param licenses: List of dictionaries, strings, or :class:`.License` objects with licensing information 34 | for data about the alloy. 35 | :param tags: List of strings or numbers that are tags for this object. 36 | :param kwargs: Dictionary of fields that are not supported. 37 | """ 38 | warn('AlloyPhase is being deprecated. Use ChemicalSystem or a subclass of it instead.') 39 | if phases is not None and sub_systems is None: 40 | sub_systems = phases 41 | super(Alloy, self).__init__(uid=uid, names=names, ids=ids, source=source, quantity=quantity, 42 | chemical_formula=chemical_formula, composition=composition, properties=properties, 43 | preparation=preparation, sub_systems=sub_systems, references=references, 44 | contacts=contacts, licenses=licenses, tags=tags, **kwargs) 45 | self.category = kwargs['category'] if 'category' in kwargs else 'system.chemical.alloy' 46 | 47 | @property 48 | def phases(self): 49 | return self._sub_systems 50 | 51 | @phases.setter 52 | def phases(self, phases): 53 | self.sub_systems = phases 54 | 55 | @phases.deleter 56 | def phases(self): 57 | del self.sub_systems 58 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/alloy/alloy_phase.py: -------------------------------------------------------------------------------- 1 | from warnings import warn 2 | from pypif.obj.system.chemical.chemical_system import ChemicalSystem 3 | 4 | 5 | class AlloyPhase(ChemicalSystem): 6 | """ 7 | Representation of a single phase in an alloy. 8 | """ 9 | 10 | def __init__(self, uid=None, names=None, ids=None, source=None, quantity=None, chemical_formula=None, 11 | composition=None, properties=None, preparation=None, sub_systems=None, references=None, 12 | contacts=None, licenses=None, tags=None, **kwargs): 13 | """ 14 | Constructor. 15 | 16 | :param uid: String with the permanent ID for this record. 17 | :param names: List of strings with common names of the alloy phase. 18 | :param ids: List of dictionaries, strings, numbers, or :class:`.Id` objects that identify the alloy phase. 19 | :param source: Dictionary, string, or :class:`.Source` object with the source of the system. 20 | :param quantity: Dictionary or :class:`.Quantity` object with the quantity of the system. 21 | :param chemical_formula: String with the chemical formula. 22 | :param composition: List of dictionaries or :class:`.Composition` objects that describe the composition of 23 | the alloy phase. 24 | :param properties: List of dictionaries or :class:`.Property` objects with properties of the alloy phase. 25 | :param preparation: List of dictionaries or :class:`.ProcessStep` objects with the preparation 26 | information of the alloy phase. 27 | :param sub_systems: List of dictionaries or :class:`.System` objects with the subsystems of the alloy phase. 28 | :param references: List of dictionaries or :class:`.Reference` objects where information about the alloy 29 | phase is published. 30 | :param contacts: List of dictionaries, strings, or :class:`.Person` objects with people to contact for 31 | information about the alloy phase. 32 | :param licenses: List of dictionaries, strings, or :class:`.License` objects with licensing information 33 | for data about the alloy phase. 34 | :param tags: List of strings or numbers that are tags for this object. 35 | :param kwargs: Dictionary of fields that are not supported. 36 | """ 37 | warn('AlloyPhase is being deprecated. Use ChemicalSystem or a subclass of it instead.') 38 | super(AlloyPhase, self).__init__(uid=uid, names=names, ids=ids, source=source, quantity=quantity, 39 | chemical_formula=chemical_formula, composition=composition, 40 | properties=properties, preparation=preparation, sub_systems=sub_systems, 41 | references=references, contacts=contacts, licenses=licenses, tags=tags, 42 | **kwargs) 43 | self.category = kwargs['category'] if 'category' in kwargs else 'system.chemical.alloy.phase' 44 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/chemical_system.py: -------------------------------------------------------------------------------- 1 | from six import string_types 2 | from pypif.obj.system.system import System 3 | from pypif.obj.system.chemical.common.composition import Composition 4 | 5 | 6 | class ChemicalSystem(System): 7 | """ 8 | Representation of a general chemical system. 9 | """ 10 | 11 | def __init__(self, uid=None, names=None, ids=None, classifications=None, source=None, quantity=None, 12 | chemical_formula=None, composition=None, properties=None, preparation=None, sub_systems=None, 13 | references=None, contacts=None, licenses=None, tags=None, **kwargs): 14 | """ 15 | Constructor. 16 | 17 | :param uid: String with the permanent ID for this record. 18 | :param names: List of strings with common names of the chemical system. 19 | :param ids: List of dictionaries, strings, numbers, or :class:`.Id` objects that identify the system. 20 | :param classifications: List of dictionaries, strings, numbers, or :class:`.Classification` objects that 21 | classify the system. 22 | :param source: Dictionary, string, or :class:`.Source` object with the source of the system. 23 | :param quantity: Dictionary or :class:`.Quantity` object with the quantity of the system. 24 | :param chemical_formula: String with the chemical formula. 25 | :param composition: List of dictionaries or :class:`.Composition` objects that describe the composition of 26 | the chemical system. 27 | :param properties: List of dictionaries or :class:`.Property` objects with properties of the system. 28 | :param preparation: List of dictionaries or :class:`.ProcessStep` objects with the preparation 29 | information of the system. 30 | :param sub_systems: List of dictionaries or :class:`.System` objects with the subsystems of the system. 31 | :param references: List of dictionaries or :class:`.Reference` objects where information about the system 32 | is published. 33 | :param contacts: List of dictionaries, strings, or :class:`.Person` objects with people to contact for 34 | information about the system. 35 | :param licenses: List of dictionaries, strings, or :class:`.License` objects with licensing information 36 | for data about the system. 37 | :param tags: List of strings or numbers that are tags for this object. 38 | :param kwargs: Dictionary of fields that are not supported. 39 | """ 40 | super(ChemicalSystem, self).__init__(uid=uid, names=names, ids=ids, classifications=classifications, 41 | source=source, quantity=quantity, properties=properties, 42 | preparation=preparation, sub_systems=sub_systems, references=references, 43 | contacts=contacts, licenses=licenses, tags=tags, **kwargs) 44 | self._chemical_formula = None 45 | self.chemical_formula = chemical_formula 46 | self._composition = None 47 | self.composition = composition 48 | self.category = kwargs['category'] if 'category' in kwargs else 'system.chemical' 49 | 50 | @property 51 | def chemical_formula(self): 52 | return self._chemical_formula 53 | 54 | @chemical_formula.setter 55 | def chemical_formula(self, chemical_formula): 56 | self._validate_type('chemical_formula', chemical_formula, string_types) 57 | self._chemical_formula = chemical_formula 58 | 59 | @chemical_formula.deleter 60 | def chemical_formula(self): 61 | self._chemical_formula = None 62 | 63 | @property 64 | def composition(self): 65 | return self._composition 66 | 67 | @composition.setter 68 | def composition(self, composition): 69 | self._validate_list_type('composition', composition, dict, Composition) 70 | self._composition = self._get_object(Composition, composition) 71 | 72 | @composition.deleter 73 | def composition(self): 74 | self._composition = None 75 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/common/__init__.py: -------------------------------------------------------------------------------- 1 | from pypif.obj.system.chemical.common.composition import Composition 2 | -------------------------------------------------------------------------------- /pypif/obj/system/chemical/common/composition.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.obj.common.pio import Pio 4 | from pypif.obj.common.scalar import Scalar 5 | 6 | 7 | class Composition(Pio): 8 | """ 9 | Class to store information about an element in a composition vector using weight percents or atomic percents. 10 | """ 11 | 12 | def __init__(self, element=None, actual_weight_percent=None, actual_atomic_percent=None, ideal_weight_percent=None, 13 | ideal_atomic_percent=None, tags=None, **kwargs): 14 | """ 15 | Constructor. 16 | 17 | :param element: Symbol of the element. 18 | :param actual_weight_percent: Actual percentage of the weight of the chemical that is this element 19 | - dictionary, string, number, or :class:`.Scalar` object. 20 | :param actual_atomic_percent: Actual percentage of the atoms in the chemical that are this element 21 | - dictionary, string, number, or :class:`.Scalar` object. 22 | :param ideal_weight_percent: Ideal percentage of the weight of the chemical that is this element 23 | - dictionary, string, number, or :class:`.Scalar` object. 24 | :param ideal_atomic_percent: Ideal percentage of the atoms in the chemical that are this element 25 | - dictionary, string, number, or :class:`.Scalar` object. 26 | :param tags: List of strings or numbers that are tags for this object. 27 | :param kwargs: Dictionary of fields that are not supported. 28 | """ 29 | super(Composition, self).__init__(tags=tags, **kwargs) 30 | self._element = None 31 | self.element = element 32 | self._actual_weight_percent = None 33 | self.actual_weight_percent = actual_weight_percent 34 | self._actual_atomic_percent = None 35 | self.actual_atomic_percent = actual_atomic_percent 36 | self._ideal_weight_percent = None 37 | self.ideal_weight_percent = ideal_weight_percent 38 | self._ideal_atomic_percent = None 39 | self.ideal_atomic_percent = ideal_atomic_percent 40 | 41 | @property 42 | def element(self): 43 | return self._element 44 | 45 | @element.setter 46 | def element(self, element): 47 | self._validate_type('element', element, string_types) 48 | self._element = element 49 | 50 | @element.deleter 51 | def element(self): 52 | self._element = None 53 | 54 | @property 55 | def actual_weight_percent(self): 56 | return self._actual_weight_percent 57 | 58 | @actual_weight_percent.setter 59 | def actual_weight_percent(self, actual_weight_percent): 60 | self._validate_type('actual_weight_percent', actual_weight_percent, dict, string_types, 61 | numbers.Number, Scalar) 62 | self._actual_weight_percent = self._get_object(Scalar, actual_weight_percent) 63 | 64 | @actual_weight_percent.deleter 65 | def actual_weight_percent(self): 66 | self._actual_weight_percent = None 67 | 68 | @property 69 | def actual_atomic_percent(self): 70 | return self._actual_atomic_percent 71 | 72 | @actual_atomic_percent.setter 73 | def actual_atomic_percent(self, actual_atomic_percent): 74 | self._validate_type('actual_atomic_percent', actual_atomic_percent, dict, string_types, 75 | numbers.Number, Scalar) 76 | self._actual_atomic_percent = self._get_object(Scalar, actual_atomic_percent) 77 | 78 | @actual_atomic_percent.deleter 79 | def actual_atomic_percent(self): 80 | self._actual_atomic_percent = None 81 | 82 | @property 83 | def ideal_weight_percent(self): 84 | return self._ideal_weight_percent 85 | 86 | @ideal_weight_percent.setter 87 | def ideal_weight_percent(self, ideal_weight_percent): 88 | self._validate_type('ideal_weight_percent', ideal_weight_percent, dict, string_types, 89 | numbers.Number, Scalar) 90 | self._ideal_weight_percent = self._get_object(Scalar, ideal_weight_percent) 91 | 92 | @ideal_weight_percent.deleter 93 | def ideal_weight_percent(self): 94 | self._ideal_weight_percent = None 95 | 96 | @property 97 | def ideal_atomic_percent(self): 98 | return self._ideal_atomic_percent 99 | 100 | @ideal_atomic_percent.setter 101 | def ideal_atomic_percent(self, ideal_atomic_percent): 102 | self._validate_type('ideal_atomic_percent', ideal_atomic_percent, dict, string_types, 103 | numbers.Number, Scalar) 104 | self._ideal_atomic_percent = self._get_object(Scalar, ideal_atomic_percent) 105 | 106 | @ideal_atomic_percent.deleter 107 | def ideal_atomic_percent(self): 108 | self._ideal_atomic_percent = None 109 | -------------------------------------------------------------------------------- /pypif/obj/system/system.py: -------------------------------------------------------------------------------- 1 | import numbers 2 | from six import string_types 3 | from pypif.obj.common.classification import Classification 4 | from pypif.obj.common.id import Id 5 | from pypif.obj.common.process_step import ProcessStep 6 | from pypif.obj.common.property import Property 7 | from pypif.obj.common.quantity import Quantity 8 | from pypif.obj.common.rcl import Rcl 9 | from pypif.obj.common.source import Source 10 | 11 | 12 | class System(Rcl): 13 | """ 14 | Base representation for all systems. 15 | """ 16 | 17 | def __init__(self, uid=None, names=None, ids=None, classifications=None, source=None, quantity=None, 18 | properties=None, preparation=None, sub_systems=None, references=None, contacts=None, 19 | licenses=None, tags=None, **kwargs): 20 | """ 21 | Constructor. 22 | 23 | :param uid: String with the permanent ID for this record. 24 | :param names: List of strings with common names of the system. 25 | :param ids: List of dictionaries, strings, numbers, or :class:`.Id` objects that identify the system. 26 | :param classifications: List of dictionaries, strings, numbers, or :class:`.Classification` objects that 27 | classify the system. 28 | :param source: Dictionary, string, or :class:`.Source` object with the source of the system. 29 | :param quantity: Dictionary or :class:`.Quantity` object with the quantity of the system. 30 | :param properties: List of dictionaries or :class:`.Property` objects with properties of the system. 31 | :param preparation: List of dictionaries or :class:`.ProcessStep` objects with the preparation 32 | information of the system. 33 | :param sub_systems: List of dictionaries or :class:`.System` objects with the subsystems of the system. 34 | :param references: List of dictionaries or :class:`.Reference` objects where information about the system 35 | is published. 36 | :param contacts: List of dictionaries, strings, or :class:`.Person` objects with people to contact for 37 | information about the system. 38 | :param licenses: List of dictionaries, strings, or :class:`.License` objects with licensing information 39 | for data about the system. 40 | :param tags: List of strings or numbers that are tags for this object. 41 | :param kwargs: Dictionary of fields that are not supported. 42 | """ 43 | super(System, self).__init__(references=references, contacts=contacts, licenses=licenses, tags=tags, **kwargs) 44 | self._uid = None 45 | self.uid = uid 46 | self._names = None 47 | self.names = names 48 | self._ids = None 49 | self.ids = ids 50 | self._classifications = None 51 | self.classifications = classifications 52 | self._source = None 53 | self.source = source 54 | self._quantity = None 55 | self.quantity = quantity 56 | self._properties = None 57 | self.properties = properties 58 | self._preparation = None 59 | self.preparation = preparation 60 | self._sub_systems = None 61 | self.sub_systems = sub_systems 62 | self.category = kwargs['category'] if 'category' in kwargs else 'system' 63 | 64 | @property 65 | def uid(self): 66 | return self._uid 67 | 68 | @uid.setter 69 | def uid(self, uid): 70 | self._validate_type('uid', uid, string_types) 71 | self._uid = uid 72 | 73 | @uid.deleter 74 | def uid(self): 75 | self._uid = None 76 | 77 | @property 78 | def names(self): 79 | return self._names 80 | 81 | @names.setter 82 | def names(self, names): 83 | self._validate_list_type('names', names, string_types) 84 | self._names = names 85 | 86 | @names.deleter 87 | def names(self): 88 | self._names = None 89 | 90 | @property 91 | def ids(self): 92 | return self._ids 93 | 94 | @ids.setter 95 | def ids(self, ids): 96 | self._validate_list_type('ids', ids, dict, string_types, numbers.Number, Id) 97 | self._ids = self._get_object(Id, ids) 98 | 99 | @ids.deleter 100 | def ids(self): 101 | self._ids = None 102 | 103 | @property 104 | def classifications(self): 105 | return self._classifications 106 | 107 | @classifications.setter 108 | def classifications(self, classifications): 109 | self._validate_list_type('classifications', classifications, dict, string_types, numbers.Number, Classification) 110 | self._classifications = self._get_object(Classification, classifications) 111 | 112 | @ids.deleter 113 | def ids(self): 114 | self._ids = None 115 | 116 | @property 117 | def source(self): 118 | return self._source 119 | 120 | @source.setter 121 | def source(self, source): 122 | self._validate_type('source', source, dict, string_types, Source) 123 | self._source = self._get_object(Source, source) 124 | 125 | @property 126 | def quantity(self): 127 | return self._quantity 128 | 129 | @quantity.setter 130 | def quantity(self, quantity): 131 | self._validate_type('quantity', quantity, dict, Quantity) 132 | self._quantity = self._get_object(Quantity, quantity) 133 | 134 | @quantity.deleter 135 | def quantity(self): 136 | self._quantity = None 137 | 138 | @source.deleter 139 | def source(self): 140 | self._source = None 141 | 142 | @property 143 | def properties(self): 144 | return self._properties 145 | 146 | @properties.setter 147 | def properties(self, properties): 148 | self._validate_list_type('properties', properties, dict, Property) 149 | self._properties = self._get_object(Property, properties) 150 | 151 | @properties.deleter 152 | def properties(self): 153 | self._properties = None 154 | 155 | @property 156 | def preparation(self): 157 | return self._preparation 158 | 159 | @preparation.setter 160 | def preparation(self, preparation): 161 | self._validate_list_type('preparation', preparation, dict, ProcessStep) 162 | self._preparation = self._get_object(ProcessStep, preparation) 163 | 164 | @preparation.deleter 165 | def preparation(self): 166 | self._preparation = None 167 | 168 | @property 169 | def sub_systems(self): 170 | return self._sub_systems 171 | 172 | @sub_systems.setter 173 | def sub_systems(self, sub_systems): 174 | self._validate_list_type('sub_systems', sub_systems, dict, System) 175 | self._sub_systems = self._get_object(System, sub_systems) 176 | 177 | @sub_systems.deleter 178 | def sub_systems(self): 179 | self._sub_systems = None 180 | -------------------------------------------------------------------------------- /pypif/obj/system/tests/test_system.py: -------------------------------------------------------------------------------- 1 | from pypif.obj import System, Property 2 | 3 | def test_create_system(): 4 | pif = System() 5 | pif.uid = "10245" 6 | pif.names = ["example", "ex"] 7 | 8 | def test_convert_to_dictionary(): 9 | pif = System() 10 | pif.uid = "10245" 11 | pif.names = ["example", "ex"] 12 | d = pif._convert_to_dictionary(pif) 13 | -------------------------------------------------------------------------------- /pypif/pif.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from pypif.obj import * 4 | from pypif.util.case import keys_to_snake_case 5 | from pypif.util.pif_encoder import PifEncoder 6 | 7 | 8 | def dump(pif, fp, **kwargs): 9 | """ 10 | Convert a single Physical Information Object, or a list of such objects, into a JSON-encoded text file. 11 | 12 | :param pif: Object or list of objects to serialize. 13 | :param fp: File-like object supporting .write() method to write the serialized object(s) to. 14 | :param kwargs: Any options available to json.dump(). 15 | """ 16 | return json.dump(pif, fp, cls=PifEncoder, **kwargs) 17 | 18 | 19 | def dumps(pif, **kwargs): 20 | """ 21 | Convert a single Physical Information Object, or a list of such objects, into a JSON-encoded string. 22 | 23 | :param pif: Object or list of objects to serialize. 24 | :param kwargs: Any options available to json.dumps(). 25 | """ 26 | return json.dumps(pif, cls=PifEncoder, **kwargs) 27 | 28 | 29 | def load(fp, class_=None, **kwargs): 30 | """ 31 | Convert content in a JSON-encoded text file to a Physical Information Object or a list of such objects. 32 | 33 | :param fp: File-like object supporting .read() method to deserialize from. 34 | :param class_: Subclass of :class:`.Pio` to produce, if not unambiguous 35 | :param kwargs: Any options available to json.load(). 36 | :return: Single object derived from :class:`.Pio` or a list of such object. 37 | """ 38 | return loado(json.load(fp, **kwargs), class_=class_) 39 | 40 | 41 | def loads(s, class_=None, **kwargs): 42 | """ 43 | Convert content in a JSON-encoded string to a Physical Information Object or a list of such objects. 44 | 45 | :param s: String to deserialize. 46 | :param class_: Subclass of :class:`.Pio` to produce, if not unambiguous 47 | :param kwargs: Any options available to json.loads(). 48 | :return: Single object derived from :class:`.Pio` or a list of such object. 49 | """ 50 | return loado(json.loads(s, **kwargs), class_=class_) 51 | 52 | 53 | def loado(obj, class_=None): 54 | """ 55 | Convert a dictionary or a list of dictionaries into a single Physical Information Object or a list of such objects. 56 | 57 | :param obj: Dictionary or list to convert to Physical Information Objects. 58 | :param class_: Subclass of :class:`.Pio` to produce, if not unambiguous 59 | :return: Single object derived from :class:`.Pio` or a list of such object. 60 | """ 61 | if isinstance(obj, list): 62 | return [_dict_to_pio(i, class_=class_) for i in obj] 63 | elif isinstance(obj, dict): 64 | return _dict_to_pio(obj, class_=class_) 65 | else: 66 | raise ValueError('expecting list or dictionary as outermost structure') 67 | 68 | 69 | def _dict_to_pio(d, class_=None): 70 | """ 71 | Convert a single dictionary object to a Physical Information Object. 72 | 73 | :param d: Dictionary to convert. 74 | :param class_: Subclass of :class:`.Pio` to produce, if not unambiguous 75 | :return: Single object derived from :class:`.Pio`. 76 | """ 77 | d = keys_to_snake_case(d) 78 | if class_: 79 | return class_(**d) 80 | if 'category' not in d: 81 | raise ValueError('Dictionary does not contains a category field: ' + ', '.join(d.keys())) 82 | elif d['category'] == 'system': 83 | return System(**d) 84 | elif d['category'] == 'system.chemical': 85 | return ChemicalSystem(**d) 86 | elif d['category'] == 'system.chemical.alloy': # Legacy support 87 | return Alloy(**d) 88 | elif d['category'] == 'system.chemical.alloy.phase': # Legacy support 89 | return ChemicalSystem(**d) 90 | raise ValueError('Dictionary does not contain a valid top-level category: ' + str(d['category'])) 91 | -------------------------------------------------------------------------------- /pypif/tests/test_pif.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from pypif.obj.common import Property, Scalar, FileReference, ProcessStep, Value, Person, Name 4 | from pypif.obj.system import System 5 | from pypif.pif import loads, dumps 6 | 7 | 8 | def test_basic_round_robin(): 9 | pif = System() 10 | pif.uid = "foo" 11 | pif2 = loads(dumps(pif)) 12 | assert pif2.uid == pif.uid 13 | 14 | 15 | def test_full_round_robin(): 16 | pif = System( 17 | properties=[ 18 | Property(name="foo", scalars=[Scalar(value=np.float32(2.4)), Scalar(value=np.int64(2))]), 19 | Property(name="bar", scalars=[Scalar(value=2.4), Scalar(value=2)]), 20 | Property(name="spam", files=[FileReference(relative_path="/tmp/file")]) 21 | ], 22 | preparation=[ProcessStep(name="processed", details=[Value(name="temp", scalars=[Scalar(value=1.0)])])], 23 | contacts=[Person(name=Name(family="Einstein"))] 24 | ) 25 | 26 | pif2 = loads(dumps(pif)) 27 | assert pif2.as_dictionary() == pif.as_dictionary(), "PIF contents are not the same" 28 | assert pif.properties[0].scalars[0].value == pif2.properties[0].scalars[0].value 29 | assert pif.properties[1].scalars[0].value == pif2.properties[1].scalars[0].value 30 | assert pif.properties[2].files[0].relative_path == pif2.properties[2].files[0].relative_path 31 | assert pif.preparation[0].details[0].scalars[0].value == pif2.preparation[0].details[0].scalars[0].value 32 | assert pif.contacts[0].name.family == pif2.contacts[0].name.family 33 | -------------------------------------------------------------------------------- /pypif/util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CitrineInformatics/pypif/0cebf8f3785616ff48593681dcc3b6710f0ed9e7/pypif/util/__init__.py -------------------------------------------------------------------------------- /pypif/util/case.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | _first_camel_case_regex = re.compile('(.)([A-Z][^A-Z]+)') 5 | _second_camel_case_regex = re.compile('([^A-Z_])([A-Z])') 6 | 7 | 8 | def to_camel_case(snake_case_string): 9 | """ 10 | Convert a string from snake case to camel case. For example, "some_var" would become "someVar". 11 | 12 | :param snake_case_string: Snake-cased string to convert to camel case. 13 | :returns: Camel-cased version of snake_case_string. 14 | """ 15 | parts = snake_case_string.lstrip('_').split('_') 16 | return parts[0] + ''.join([i.title() for i in parts[1:]]) 17 | 18 | 19 | def to_capitalized_camel_case(snake_case_string): 20 | """ 21 | Convert a string from snake case to camel case with the first letter capitalized. For example, "some_var" 22 | would become "SomeVar". 23 | 24 | :param snake_case_string: Snake-cased string to convert to camel case. 25 | :returns: Camel-cased version of snake_case_string. 26 | """ 27 | parts = snake_case_string.split('_') 28 | return ''.join([i.title() for i in parts]) 29 | 30 | 31 | def to_snake_case(camel_case_string): 32 | """ 33 | Convert a string from camel case to snake case. From example, "someVar" would become "some_var". 34 | 35 | :param camel_case_string: Camel-cased string to convert to snake case. 36 | :return: Snake-cased version of camel_case_string. 37 | """ 38 | first_pass = _first_camel_case_regex.sub(r'\1_\2', camel_case_string) 39 | return _second_camel_case_regex.sub(r'\1_\2', first_pass).lower() 40 | 41 | 42 | def keys_to_snake_case(camel_case_dict): 43 | """ 44 | Make a copy of a dictionary with all keys converted to snake case. This is just calls to_snake_case on 45 | each of the keys in the dictionary and returns a new dictionary. 46 | 47 | :param camel_case_dict: Dictionary with the keys to convert. 48 | :type camel_case_dict: Dictionary. 49 | 50 | :return: Dictionary with the keys converted to snake case. 51 | """ 52 | return dict((to_snake_case(key), value) for (key, value) in camel_case_dict.items()) 53 | -------------------------------------------------------------------------------- /pypif/util/pif_encoder.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | import numpy as np 4 | 5 | 6 | class PifEncoder(json.JSONEncoder): 7 | """ 8 | Class to convert physical information objects to json. 9 | """ 10 | 11 | def default(self, obj): 12 | """ 13 | Convert an object to a form ready to dump to json. 14 | 15 | :param obj: Object being serialized. The type of this object must be one of the following: None; a single 16 | object derived from the Pio class; or a list of objects, each derived from the Pio class. 17 | :return: List of dictionaries, each representing a physical information object, ready to be serialized. 18 | """ 19 | if obj is None: 20 | return [] 21 | elif isinstance(obj, list): 22 | return [i.as_dictionary() for i in obj] 23 | elif hasattr(obj, 'as_dictionary'): 24 | return obj.as_dictionary() 25 | elif isinstance(obj, (np.int_, np.intc, np.intp, np.int8, np.int16, np.int32, 26 | np.int64, np.uint8, np.uint16, np.uint32, np.uint64)): 27 | return int(obj) 28 | elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)): 29 | return float(obj) 30 | return json.JSONEncoder.default(self, obj) 31 | -------------------------------------------------------------------------------- /pypif/util/serializable.py: -------------------------------------------------------------------------------- 1 | from pypif.util.case import to_camel_case 2 | from pypif.util.case import keys_to_snake_case 3 | 4 | 5 | class Serializable(object): 6 | """ 7 | Base class for objects that can be serialized. 8 | """ 9 | 10 | def as_dictionary(self): 11 | """ 12 | Convert this object to a dictionary with formatting appropriate for a PIF. 13 | 14 | :returns: Dictionary with the content of this object formatted for a PIF. 15 | """ 16 | return {to_camel_case(i): Serializable._convert_to_dictionary(self.__dict__[i]) 17 | for i in self.__dict__ if self.__dict__[i] is not None} 18 | 19 | @staticmethod 20 | def _convert_to_dictionary(obj): 21 | """ 22 | Convert obj to a dictionary with formatting appropriate for a PIF. This function attempts to treat obj as 23 | a Pio object and otherwise returns obj. 24 | 25 | :param obj: Object to convert to a dictionary. 26 | :returns: Input object as a dictionary or the original object. 27 | """ 28 | if isinstance(obj, list): 29 | return [Serializable._convert_to_dictionary(i) for i in obj] 30 | elif hasattr(obj, 'as_dictionary'): 31 | return obj.as_dictionary() 32 | else: 33 | return obj 34 | 35 | @staticmethod 36 | def _get_object(class_, obj): 37 | """ 38 | Helper function that returns an object, or if it is a dictionary, initializes it from class_. 39 | 40 | :param class_: Class to use to instantiate object. 41 | :param obj: Object to process. 42 | :return: One or more objects. 43 | """ 44 | if isinstance(obj, list): 45 | return [Serializable._get_object(class_, i) for i in obj] 46 | elif isinstance(obj, dict): 47 | return class_(**keys_to_snake_case(obj)) 48 | else: 49 | return obj 50 | -------------------------------------------------------------------------------- /pypif/util/tests/test_case.py: -------------------------------------------------------------------------------- 1 | from pypif.util.case import to_snake_case 2 | 3 | 4 | def test_to_snake_case(): 5 | assert to_snake_case("relativePath") == "relative_path" -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.15.3 2 | six==1.11.0 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | [bdist_wheel] 4 | universal=1 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup(name='pypif', 4 | version='2.1.2', 5 | url='http://github.com/CitrineInformatics/pypif', 6 | description='Python tools for working with the Physical Information File (PIF)', 7 | author='Citrine Informatics', 8 | packages=find_packages(), 9 | install_requires=[ 10 | 'six>=1.10.0,<2', 11 | 'numpy' 12 | ]) 13 | --------------------------------------------------------------------------------