add setup

This commit is contained in:
2019-02-08 16:05:51 +01:00
parent e6f553d169
commit e9973b1bbf
6 changed files with 34 additions and 0 deletions

135
src/data/INFO.json Normal file
View File

@@ -0,0 +1,135 @@
[{
"Name": "Name of the material",
"Formula": "Formula of the material",
"Heat treatment": {
"Hardening": "Precipitation hardening or age hardening or particle hardening",
"Temper": "Tempering relieves stresses in the metal that were caused by the hardening process. precipitation hardening"
},
"CAS Reg No.": "Chemical Abstracts Service Registry Number",
"Mol. weight": "Molecular weight (relative molar mass)",
"Physical Form": {
"color": "color of the material",
"crystal": "crystal type of the material, e. g. cubic"
},
"Equilibrium": {
"p": "pressure",
"rho": "Density at pressure p and temperature T",
"T": "Temperature",
"T_m": "Normal melting point at pressure p",
"T_b": "Normal boiling point at vapor pressure p"
},
"rho(T)": {
"rho_m": "Estimated density at higher temperatures (up to Tmax or about 20°C): \\[\\rho(T)=\\rho\\ti{m}-k(T-T_m)\\]",
"k": "",
"T_max": "The maximum temperature for the estimated density"
},
"p_b(T)": "Vapor pressure \\(p\\) in pascals: \\[\\log(p/Pa) = 5.006 + A + BT^{-1} + C\\log{T} + DT^3\\] where temperature T in K; p. 6-72",
"Electromagnetic Data": {
"chi_m": "Magnetic susceptibility; Molar susceptibility \\[\\chi\\ti{m} = \\kappa V\\ti{m} = \\kappa M / \\rho \\] where \\(\\kappa\\) is the volume susceptibility, \\(V\\ti{m}\\) is the molar volume of the substance, \\(M\\) the molar mass, and \\(\\rho\\) the mass density. \\(\\kappa = \\bold{M}/\\bold{H}\\) where \\(\\bold{H}\\) is the magnetic filed and \\(\\bold{M}\\) is magnetic moment per unit volume.",
"sigma": "Electrical conductivity"
},
"Mechanical Properties": {
"T": "Reference temperature",
"rho": "Density",
"E": "Young modulus, module of elasticity",
"R_p02": "Yield strength R_e, R_{p0.2}",
"R_m": "Ultimate tensile strength R_m",
"Elongation": "A_5",
"Hardness": {
"HBW": ""
}
},
"Thermodynamic Properties": {
"Crystal, Liquid, Gas": {
"alpha": "Coefficient of thermal expansion",
"k": "Thermal conductivity",
"Delta_f H°": "Standard molar enthalpy (heat) of formation at 298.15 K in kJ/mol. 0.0 indicates the reference state.",
"Delta_f G°": "Standard molar Gibbs energy of formation at 298.15 K in kJ/mol",
"S°": "Standard molar entropy at 298.15 K in J/mol/K",
"cp": "Specific heat capacity",
"Cp": "Molar heat capacity at constant pressure at 298.15 K in J/mol/K"
},
"Delta_vap H": "Molar enthalpy (heat) of vaporization. Values are given at a pressure of 101.325 kPa",
"Delta_fus H": "Molar enthalpy (heat) of fusion. Values are given at the normal melting point Tm"
},
"Crystallographic Data": {
"Structure type": "Prototype for the structural arrangement of the crystallographic cell.",
"Z": "Number of formula units per the unit cell.",
"a, b, c": "Length of the cell edges in Å (1 Å = 10e-8 cm)",
"alpha, beta, gamma": "Angles between cell axes"
},
"Cubic Crystal": {
"rho": "Density",
"T": "Temperature",
"C11, C12, C44": ""
},
"Dynamik viscosity mu(T)": "List of temperature and viscosity values.",
"Human": {
"Constituents of Human Blood": {
"Total volume of blood": "7.5 L for a male and 6.7 L for a female in 100 kg adult.",
"Total volume of plasma": "4.4 L for a male and 4.3 L for a female in 100 kg adult."
},
"Composition of the Human Body": "Standard man = 70 kg"
},
"Borax Beads": {
"Oxidizing flame, Reducing flame": {
"colorless": "value or list of values of 'default', 'hot', 'cold', 'not saturated'",
"opaque": "value or list of values of 'supersaturated', 'saturated'"
}
},
"Source": "Sources"
},
{
"Name": "Name of the material",
"Alloy": {
"Standard": "EN AW xxxx",
"Type": "non heat-treatable"
},
"Formula": "Al, AlMg4.5Mn0.7",
"Heat treatment": {
"Temper": "homogenized and stress relieved, O3"
},
"CAS Reg No.": "7429-90-5",
"Mol. weight": 26.982,
"Physical Form": {
"color": "silvery-white metal",
"crystal": "cubic|cubic crystals"
},
"Electromagnetic Data": {
"chi_m": [16.5e-6, "cm³/mol"],
"sigma": ["16-18", "m/Ω/mm²"]
},
"Mechanical Properties": {
"T": ["20-25", "°C"],
"rho": [2.66, "g/cm³"],
"E": [70, "GPa"],
"R_p02": ["110-130", "MPa"],
"R_m": ["230-290", "MPa"],
"Elongation": ["10-15", "%"],
"Hardness": {
"HBW": ["68-75", "2.5/62.5"]
}
},
"Thermodynamic Properties": {
"Crystal": {
"alpha": [23.3, "m/µm/K"],
"k": ["110-130", "W/m/K"],
"cp": [900, "J/kg/K"]
}
},
"Source": [
{
"Type": "Book",
"Title": "Title of the book",
"Pages": [
["4-152", "Electromagnetic Data"],
["4-156", "Crystallographic Data"],
["8-13", "Borax Beads"]
]
},
{
"Type": "Web",
"URL": "http://"
}
]
}]

189
src/data/aluminum.json Normal file
View File

@@ -0,0 +1,189 @@
[{
"Name": "Aluminum",
"Formula": "Al",
"CAS Reg No.": "7429-90-5",
"Mol. weight": 26.982,
"Physical Form": {
"color": "silvery-white metal",
"crystal": "cubic crystals"
},
"Equilibrium": [
{
"p": [1, "Pa"],
"T_b": [1209, "°C"]
},
{
"p": [10, "Pa"],
"T_b": [1359, "°C"]
},
{
"p": [100, "Pa"],
"T_b": [1544, "°C"]
},
{
"p": [1, "kPa"],
"T_b": [1781, "°C"]
},
{
"p": [10, "kPa"],
"T_b": [2091, "°C"]
},
{
"p": [100, "kPa"],
"T_b": [2517, "°C"]
},
{
"p": [101.325, "kPa"],
"rho": [2.70, "g/cm³"],
"T": [25, "°C"],
"T_m": [660.32, "°C"],
"T_b": [2519, "°C"]
}
],
"rho(T)": {
"rho_m": [2.375, "g/cm³"],
"k": [0.000233, "g/cm³/°C"],
"T_max": [1340, "°C"]
},
"p_b(T)": {
"Solid": {
"A": 9.459,
"B": -17342,
"C": -0.7927,
"D": null,
"Range in K": "298-Tm"
},
"Liquid": {
"A": 5911,
"B": -16211,
"C": null,
"D": null,
"Range in K": "Tm-1800"
}
},
"Electromagnetic Data": {
"chi_m": [16.5e-6, "cm³/mol"]
},
"Thermodynamic Properties": {
"Crystal": {
"Delta_f H°": [0.0, "kJ/mol"],
"Delta_f G°": null,
"S°": [28.3, "J/mol/K"],
"cp": [0.897, "J/g/K"],
"Cp": [24.20, "J/mol/K"]
},
"Liquid": null,
"Gas": {
"Delta_f H°": [330.0, "kJ/mol"],
"Delta_f G°": [289.4, "kJ/mol"],
"S°": [164.6, "J/mol/K"],
"Cp": [21.4, "J/mol/K"]
},
"Delta_vap H": [
{
"T": [2519, "°C"],
"Delta_vap H": [294, "kJ/mol"]
}
],
"Delta_fus H": [10.71, "kJ/mol"]
},
"Crystallographic Data": {
"Crystal system": "cubic",
"Structure type": "copper",
"Z": 4,
"a": [4.049, "Å"],
"b": null,
"c": null,
"alpha": null,
"beta": null,
"gamma": null
},
"Cubic Crystal": {
"rho": [2.6970, "g/cm³"],
"T": [298, "K"],
"C11": [1.0675e11, "N/m²"],
"C12": [0.6041e11, "N/m²"],
"C44": [0.2834e11, "N/m²"]
},
"Dynamic viscosity mu(T)": [
{
"T": [700, "°C"],
"mu": [1.289, "mPa s"]
},
{
"T": [750, "°C"],
"mu": [1.200, "mPa s"]
},
{
"T": [800, "°C"],
"mu": [1.115, "mPa s"]
},
{
"T": [850, "°C"],
"mu": [1.028, "mPa s"]
}
],
"Human": {
"Constituents of Human Blood": {
"Blood sample": "serum",
"Normal Low": [1, "µg/L"],
"Normal High": [10, "µg/L"],
"Critical": [">60", "µg/L"]
},
"Composition of the Human Body": {
"Amount": [0.061, "g"],
"Percent of total body mass": 0.00009
}
},
"Borax Beads": {
"Oxidizing flame": {
"colorless": ["hot", "cold", "not saturated"],
"opaque": "supersaturated"
},
"Reducing flame": {
"colorless": "default",
"opaque": "saturated"
}
},
"Source": {
"Type": "Book",
"Title" : "",
"Pages": [694, 758, 760, 764, 767, 781, 792, 978, 1017, 1035, 1122, 1179, 1182, 1207]
}
},
{
"Name": "G.AL® C250 Aluminium Präzisionsplatte",
"Alloy": {
"Standard": "EN AW 5083",
"Type": "non heat-treatable"
},
"Formula": "AlMg4.5Mn0.7",
"Heat treatment": {
"Temper": "homogenized and stress relieved, O3"
},
"Electromagnetic Data": {
"sigma": ["16-18", "m/Ω/mm²"]
},
"Mechanical Properties": {
"T": ["20-25", "°C"],
"rho": [2.66, "g/cm³"],
"E": [70, "GPa"],
"R_p02": ["110-130", "MPa"],
"R_m": ["230-290", "MPa"],
"Elongation": ["10-15", "%"],
"Hardness": {
"HBW": ["68-75", "2.5/62.5"]
}
},
"Thermodynamic Properties": {
"Crystal": {
"alpha": [23.3, "m/µm/K"],
"k": ["110-130", "W/m/K"],
"cp": [900, "J/kg/K"]
}
},
"Source": {
"Type": "Web",
"URL": "https://gleich.de/en/wp-content/uploads/sites/4/2016/10/en_g.al_c250.pdf"
}
}]

175
src/materials.py Executable file
View File

@@ -0,0 +1,175 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""\
Material database.
"""
__author__ = "Daniel Weschke"
__copyright__ = "Copyright 2019 Daniel Weschke"
__credits__ = ["Daniel Weschke"]
__license__ = "MIT"
__version__ = "2019.02.03"
__maintainer__ = "Daniel Weschke"
__email__ = "daniel.weschke@directbox.de"
__status__ = "Production" # "Prototype", "Development", "Production"
VERSION = """\
%(prog)s version {version} {copyright}
""".format(
version=__version__, copyright=__copyright__)
EPILOG = """\
"""
def read_dir(dir, exclude=[]):
"""\
Read all files in directory as list
"""
from os import listdir
result = []
for data in listdir(dir):
file_name = data.split('.')[0]
if file_name not in exclude:
result.append(file_name)
return result
def print_list(list):
"""\
Print list
"""
for data in list:
print(data.title())
def read_file(input_file):
"""\
Read file as string
"""
try:
with open(input_file) as data_file:
return data_file.read()
except (OSError, IOError) as err:
print(str(err))
sys.exit(2)
def print_data(data):
"""\
Convert string data to json data and print it.
"""
from json import loads
from pprint import pprint
#print(data)
pprint(loads(data))
def search_keys(data, keys=None):
"""\
Search for json keys in string data
"""
from json import loads
def find_values(key, json_repr):
results = []
def _decode_dict(a_dict):
try:
results.append(a_dict[key])
except KeyError:
pass
return a_dict
loads(json_repr, object_hook=_decode_dict) # return value ignored
return results
if keys is not None:
for key in keys:
found_values = find_values(key, data)
#print(found_values)
for value in found_values:
print(key + ' = ' + '%s' % value[0] + ' ' + value[1])
#def getLength(element):
# try:
# element.__iter__
# return sum([getLength(i) for i in element])
# except:
# return 1
#print(len(data))
#print(getLength(json.loads(data)))
def main():
"""\
Main function
"""
from os import path
import argparse
parser = argparse.ArgumentParser(
description=__doc__, prefix_chars='-', epilog=EPILOG,
#usage="%(prog)s [OPTION]... NAME",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument('-v', '--verbose', action="store_true", help="Verbose output")
parser.add_argument('-V', '--version', action='version', version=VERSION)
parser.add_argument('-D', '--debug', dest='debug', action='store_true', help=argparse.SUPPRESS)
subparsers = parser.add_subparsers(help='commands', dest='command')
# list materials
parser_list = subparsers.add_parser('list',
description='List materials.',
help='list all available materials')
# get material
parser_get = subparsers.add_parser('get',
description='Get material information.',
help='get material information')
parser_get.add_argument('materialname', action='store',
help='list available material information')
parser_get.add_argument('-r', '--rho', dest='const_collection',
action='append_const', const="rho",
help='get density from material')
parser_get.add_argument('-T', '--Tm', dest='const_collection',
action='append_const', const="T_m",
help='get melting point temperature')
parser_get.add_argument('--search', action='store',
help='search for material information, comma delimited keys')
args = parser.parse_args()
if args.debug:
print(args)
if args.command == 'list':
list = read_dir("./data", "INFO")
print_list(list)
elif args.command == 'get':
filename = path.join('data', args.materialname + '.json')
data = read_file(filename)
if args.debug:
print("filename: " + filename)
if args.const_collection:
if "rho" in args.const_collection:
args.const_collection.append("rho(T)")
if args.debug:
print(args)
#search_keys(data, keys=args.const_collection)
elif args.search:
search_list = [element for element in args.search.split(',')]
if args.debug:
print("search_list: " + str(search_list))
search_keys(data, keys=search_list)
else:
print_data(data)
return 0
if __name__ == "__main__":
import sys
sys.exit(main())