Modul:Homokozó/JulesWinnfield-hu/Modul:Kembox/Chembox Properties

A Wikipédiából, a szabad enciklopédiából

Homokozó/JulesWinnfield-hu/Modul:Kembox/Chembox Properties[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local csopfej = "Kémiai és fizikai tulajdonságok"

local boxtbl = {   -- a paraméterek sorrendje és infóboxbeli felirata. Az 1-es sorszám fenntartva csopfej-nek.
        Formula                 = { 2, "[[Kémiai képlet]]" },
--                                                         -- a 3-as sorszám fenntartva MolarMass-nak (lásd alább)
        Appearance              = { 4, "Megjelenés" }, 
        ["halmazállapot"]       = { 5, "[[Halmazállapot]]" }, 
        Odor                    = { 6, "[[Szag]]" }, 
        Density                 = { 7, "[[Sűrűség]]" }, 
--                                                         -- a 8-as sorszám fenntartva MeltingPt-nak (lásd alább)
--                                                         -- a 9-as sorszám fenntartva BoilingPt-nak (lásd alább)
        SublimationConditions   = { 10, "A [[szublimáció]]<br>feltételei" }, 
        Solubility              = { 11, "[[Oldhatóság]] (vízben)" },
--                                                         -- a 12--17-es sorszám fenntartva az oldhatóságoknak
--                                                         -- a 18-as sorszám fenntartva SolubilityProduct-nak
        ["oldószerei"]          = { 19, "[[Oldószer]]ei" },
        pKa                     = { 20, "[[Savi disszociációs állandó|Savasság]] (p''K''<sub>a</sub>)" },
        pKb                     = { 21, "[[Savi disszociációs állandó|Lúgosság]] (p''K''<sub>b</sub>)" },
        IsoelectricPt           = { 22, "Izoelektromos pont" },
        LambdaMax               = { 23, "[[Lambda-max|λ<sub>max<sub>]]" },
        Absorbance              = { 24, "[[Abszorbancia]]" },
        BandGap                 = { 25, "[[Tiltott sáv]]"  },
        ElectronMobility        = { 26, "ElektronMobilitás" },
        SpecRotation            = { 27, "[[Fajlagos forgatóképesség]] [α]<sub>D</sub>" },
        MagSus                  = { 28, "Mágneses szuszceptibilitás" },
        ThermalConductivity     = { 29, "Hővezetés" },
        RefractIndex            = { 30, "[[Törésmutató]] (''n''<sub>D</sub>)" },
        Viscosity               = { 31, "[[Viszkozitás]]" },
        ["felületi feszültség"] = { 32, "[[Felületi feszültség]]" },
        CriticalRelativeHumidity= { 33, "Kritikus relatív páratartalom" },
        Dipole                  = { 34, "Dipólusmomentum" },
        OrbitalHybridisation    = { 35, "Hibridizáció" },
        VaporPressure           = { 36, "[[Gőznyomás]]" },
        HenryConstant           = { 37, "[[Henry törvénye|k<sub>H</sub>]]" },
        LogP                    = { 38, "[[log P|Megoszlási hányados]]" },
        AtmosphericOHRateConstant={ 39, "AtmosphericOHRateConstant" },
        }

local szintbl = {  -- szinonimaszótár. Programon belül Chembox_new neveit használjuk.
        ["Képlet"]              = 'Formula',               -- Chembox_új, Gyógyszeresdoboz
        ["kémiai_képlet"]       = 'Formula',               -- Vegyület_infobox
        ["chemical_formula"]    = 'Formula',               -- Drugbox
        ["Töltés"]              = 'charge',                -- Gyógyszeresdoboz
        ["MolárisTömeg"]        = 'MolarMass',             -- Chembox_új
        ["moláris_tömeg"]       = 'MolarMass',             -- Vegyület_infobox
        ["molecular_weight"]    = 'MolarMass',             -- Drugbox
        ["MolekulaTömeg"]       = 'MolarMass',             -- Gyógyszeresdoboz
        ["MolárisTömeg_megj"]   = 'MolarMass_notes',       -- Chembox_új
        ["Megjelenés"]          = 'Appearance',            -- Chembox_új
        ["megjelenés"]          = 'Appearance',            -- Vegyület_infobox
        ["Odour"]               = 'Odor',                  -- Chembox_new
        ["Szag"]                = 'Odor',                  -- Chembox_új
        ["Sűrűség"]             = 'Density',               -- Chembox_új, Gyógyszeresdoboz
        ["sűrűség"]             = 'Density',               -- Vegyület_infobox
        ["density"]             = 'Density',               -- Drugbox
        ["Olvadáspont"]         = 'MeltingPt',             -- Chembox_új, Gyógyszeresdoboz      olvadáspontok
        ["olvadáspont"]         = 'MeltingPt',             -- Vegyület_infobox
        ["Olvadáspont_megj"]    = 'Melting_notes',         -- Chembox_új
        ["melting_notes"]       = 'Melting_notes',         -- Drugbox
        ["OlvadásMegj"]         = 'Melting_notes',         -- Gyógyszeresdoboz
        ["MeltingPtCL"]         = 'MeltingPtC',            -- Chembox_new
        ["OlvadáspontC"]        = 'MeltingPtC',            -- Chembox_új
        ["OlvadáspontCL"]       = 'MeltingPtC',            -- Chembox_új
        ["melting_point"]       = 'MeltingPtC',            -- Drugbox
        ["OlvadáspontCH"]       = 'MeltingPtCH',           -- Chembox_új
        ["melting_high"]        = 'MeltingPtCH',           -- Drugbox
        ["OlvadásMax"]          = 'MeltingPtCH',           -- Gyógyszeresdoboz
        ["MeltingPtFL"]         = 'MeltingPtFL',           -- Chembox_new
        ["OlvadáspontF"]        = 'MeltingPtFL',           -- Chembox_új
        ["OlvadáspontFL"]       = 'MeltingPtFL',           -- Chembox_új
        ["OlvadáspontFH"]       = 'MeltingPtFH',           -- Chembox_új
        ["MeltingPtKL"]         = 'MeltingPtK',            -- Chembox_new
        ["OlvadáspontK"]        = 'MeltingPtK',            -- Chembox_új
        ["OlvadáspontKL"]       = 'MeltingPtK',            -- Chembox_új
        ["OlvadáspontKH"]       = 'MeltingPtKH',           -- Chembox_új
        ["Forráspont"]          = 'BoilingPt',             -- Chembox_új, Gyógyszeresdoboz      forráspontok
        ["forráspont"]          = 'BoilingPt',             -- Vegyület_infobox
        ["Forráspont_megj"]     = 'Boiling_notes',         -- Chembox_új
        ["boiling_notes"]       = 'Boiling_notes',         -- Drugbox
        ["ForrásMegj"]          = 'Boiling_notes',         -- Gyógyszeresdoboz
        ["BoilingPtCL"]         = 'BoilingPtC',            -- Chembox_new
        ["ForráspontC"]         = 'BoilingPtC',            -- Chembox_új
        ["ForráspontCL"]        = 'BoilingPtC',            -- Chembox_új
        ["boiling_point"]       = 'BoilingPtC',            -- Drugbox
        ["ForráspontCH"]        = 'BoilingPtCH',           -- Chembox_új
        ["BoilingPtFL"]         = 'BoilingPtFL',           -- Chembox_new
        ["ForráspontF"]         = 'BoilingPtFL',           -- Chembox_új
        ["ForráspontFL"]        = 'BoilingPtFL',           -- Chembox_új
        ["ForráspontFH"]        = 'BoilingPtFH',           -- Chembox_új
        ["BoilingPtKL"]         = 'BoilingPtK',            -- Chembox_new
        ["ForráspontK"]         = 'BoilingPtK',            -- Chembox_új
        ["ForráspontKL"]        = 'BoilingPtK',            -- Chembox_új
        ["ForráspontKH"]        = 'BoilingPtKH',           -- Chembox_új
        ["SzublimációFeltétel"] = 'SublimationConditions', -- Chembox_új                         egyéb        
        ["Oldhatóság"]          = 'Solubility',            -- Chembox_új
        ["oldhatóság_vízben"]   = 'Solubility',            -- Vegyület_infobox
        ["solubility"]          = 'Solubility',            -- Drugbox
        ["Oldószer"]            = 'Solvent',               -- Chembox_új
        ["OldhatóságProduct"]   = 'SolubilityProduct',     -- Chembox_új
        ["OldhatóságProductAs"] = 'SolubilityProductAs',   -- Chembox_új
        ["savasság"]            = 'pKa',                   -- Vegyület_infobox
        ["lúgosság"]            = 'pKb',                   -- Vegyület_infobox
        ["IzoelektromosPont"]   = 'IsoelectricPt',         -- Chembox_új
        ["Abszorbancia"]        = 'Absorbance',            -- Chembox_új
        ["ElektronMobilitás"]   = 'ElectronMobility',      -- Chembox_új
        ["SpecRotáció"]         = 'SpecRotation',          -- Chembox_új
        ["specific_rotation"]   = 'SpecRotation',          -- Drugbox
        ["FajlagosForgatás"]    = 'SpecRotation',          -- Gyógyszeresdoboz
        ["Hővezetés"]           = 'ThermalConductivity',   -- Chembox_új
        ["Törésmutató"]         = 'RefractIndex',          -- Chembox_új
        ["törésmutató"]         = 'RefractIndex',          -- Vegyület_infobox
        ["Viszkozitás"]         = 'Viscosity',             -- Chembox_új
        ["viszkozitás"]         = 'Viscosity',             -- Vegyület_infobox
        ["KritikusRelPáratartalom"] = 'CriticalRelativeHumidity', -- Chembox_új
        ["Dipólus"]             = 'Dipole',                -- Chembox_új
        ["dipólusmomentum"]     = 'Dipole',                -- Vegyület_infobox
        ["OrbitálHibridizáció"] = 'OrbitalHybridisation',  -- Chembox_új
        ["Gőznyomás"]           = 'VaporPressure',         -- Chembox_új
        ["gőznyomás"]           = 'VaporPressure',         -- Vegyület_infobox
        ["HenryÁllandó"]        = 'HenryConstant',         -- Chembox_új
        ["Henry-állandó"]       = 'HenryConstant',         -- Vegyület_infobox
        ["megoszlási_hányados"] = 'LogP',                  -- Vegyület_infobox
        ["LégköriOHSebÁll"]     = 'AtmosphericOHRateConstant',  -- Chembox_új
        }

local elemek = {	-- 2013.09.24-i IUPAC-állapot
	H   = 1.00794,
	He  = 4.002602,
	Li  = 6.941,
	Be  = 9.0121831,
	B   = 10.811,
	C   = 12.0107,
	N   = 14.0067,
	O   = 15.9994,
	F   = 18.998403163,
	Ne  = 20.1797,
	Na  = 22.98976928,
	Mg  = 24.3050,
	Al  = 26.9815385,
	Si  = 28.0855,
	P   = 30.973761998,
	S   = 32.065,
	Cl  = 35.453,
	Ar  = 39.948,
	K   = 39.0983,
	Ca  = 40.078,
	Sc  = 44.955908,
	Ti  = 47.867,
	V   = 50.9415,
	Cr  = 51.9961,
	Mn  = 54.938044,
	Fe  = 55.845,
	Co  = 58.933194,
	Ni  = 58.6934,
	Cu  = 63.546,
	Zn  = 65.38,
	Ga  = 69.723,
	Ge  = 72.64,
	As  = 74.921595,
	Se  = 78.971,
	Br  = 79.904,
	Kr  = 83.798,
	Rb  = 85.4678,
	Sr  = 87.62,
	Y   = 88.90584,
	Zr  = 91.224,
	Nb  = 92.90637,
	Mo  = 95.95,
	Tc  = 98.9063,
	Ru  = 101.07,
	Rh  = 102.90550,
	Pd  = 106.42,
	Ag  = 107.8682,
	Cd  = 112.414,
	In  = 114.818,
	Sn  = 118.710,
	Sb  = 121.760,
	Te  = 127.60,
	I   = 126.90447,
	Xe  = 131.293,
	Cs  = 132.90545196,
	Ba  = 137.327,
	La  = 138.90547,
	Ce  = 140.116,
	Pr  = 140.90766,
	Nd  = 144.242,
	Pm  = 146.9151,
	Sm  = 150.36,
	Eu  = 151.964,
	Gd  = 157.25,
	Tb  = 158.92535,
	Dy  = 162.500,
	Ho  = 164.93033,
	Er  = 167.259,
	Tm  = 168.93422,
	Yb  = 173.054,
	Lu  = 174.9668,
	Hf  = 178.49,
	Ta  = 180.94788,
	W   = 183.84,
	Re  = 186.207,
	Os  = 190.23,
	Ir  = 192.217,
	Pt  = 195.084,
	Au  = 196.966569,
	Hg  = 200.59,
	Tl  = 204.3833,
	Pb  = 207.2,
	Bi  = 208.98040,
	Po  = 208.9824,
	At  = 209.9871,
	Rn  = 222.0176,
	Fr  = 223.0197,
	Ra  = 226.0254,
	Ac  = 227.0278,
	Th  = 232.0377,
	Pa  = 231.03588,
	U   = 238.02891,
	Np  = 237.0482,
	Pu  = 244.0642,
	Am  = 243.0614,
	Cm  = 247.0704,
	Bk  = 247.0703,
	Cf  = 251.0796,
	Es  = 252.0830,
	Fm  = 257.0951,
	Md  = 258.0984,
	No  = 259.1010,
	Lr  = 262.1096,
	Rf  = 267.1215,
	Db  = 268.1255,
	Sg  = 271.1335,
	Bh  = 272.1380,
	Hs  = 277.150,
	Mt  = 276.1512,
	Ds  = 281.162,
	Rg  = 280.1645,
	Uub = 285.174,
	Uut = 284.178,
	Uuq = 289.189,
	Uup = 288.192,
	Uuh = 293,
	Uus = 0,
	Uuo = 294,
}
local elemhiba = false;  -- minden elem darabszáma 0-nál nagyobb szám kell legyen.

function nilstr(str)     -- nil-ből üres stringet csinál
if str == nil then return "" else return str end
end

function tohuszam(str)   -- tizedespont -> tizedesvessző
return string.gsub(str,'%.',',')
end


local munka    = {}      -- { { sorsz, címke }, érték }
local uto      = { MassRound = 2 }       -- utófeldolgozást igénylő paraméterek (egy eredménysor több paraméterből áll elő)
local molekula = {}

function egysor(nev,v)
    local utotbl = {     -- automatikusan uto-ba kerülő paraméterek listája. A true nem kell, de enélkül nem lesz asszociatív a tömb.
          charge              = true,
          MolarMass           = true,
          MolarMass_notes     = true,
          MassRound           = true,
          MeltingPt           = true,
          Melting_notes       = true,
          MeltingPtC          = true,
          MeltingPtCH         = true,
          BoilingPt           = true,
          Boiling_notes       = true,
          BoilingPtC          = true,
          BoilingPtCH         = true,
          SolubleOther        = true,
          Solvent             = true,
          Solubility1         = true,
          Solvent1            = true,
          Solubility2         = true,
          Solvent2            = true,
          Solubility3         = true,
          Solvent3            = true,
          Solubility4         = true,
          Solvent4            = true,
          Solubility5         = true,
          Solvent5            = true,
          SolubilityProduct   = true,
          SolubilityProductAs = true,
          }

    n = string.gsub(nev,' ','_')
    if szintbl[n] then n = szintbl[n] end      -- n a Chembox_new-beli név 
    if hivo ~= 'Vegyület_infobox' and elemek[n]
    then   if v and tonumber(v)~=nil and #v > 0  --  a paraméter pl. C = 3  (n=C, v=3)
           then   table.insert(molekula,{n,v})
           else   elemhiba = true;
           end 
    elseif boxtbl[n]    -- a boxtbl tábla (lásd feljebb) az ismert paramétereket és azok sorrendjét tartalmazza
    then   if n == 'Formula' and v and #v > 0 then uto[n] = v end      -- megadta az összegképletet, a sajátunkat nem kell kiírni
           if v and #v > 0 then table.insert(munka,{boxtbl[n],v}) end  -- az üres paramétereket nem írjuk ki
    end 
    if utotbl[n] and v and #v > 0 then uto[n] = v  end -- a második menetben feldolgozandó paraméter: az elsőben nincs vele tennivaló
    if v and #v > 0 
    then   if     n == 'MeltingPtF'  then uto.MeltingPtC  = string.format('%1.0f',(v-32)*5/9)       -- a Fahrenheit-fokot átszámítjuk °C-ra
           elseif n == 'MeltingPtFH' then uto.MeltingPtCH = string.format('%1.0f',(v-32)*5/9)       -- a Fahrenheit-fokot átszámítjuk °C-ra
           elseif n == 'MeltingPtK'  then uto.MeltingPtC  = string.format('%1.0f',v-273.15)         -- a Kelvin-fokot átszámítjuk °C-ra
           elseif n == 'MeltingPtKH' then uto.MeltingPtCH = string.format('%1.0f',v-273.15)         -- a Kelvin-fokot átszámítjuk °C-ra
           elseif n == 'BoilingPtF'  then uto.BoilingPtC  = string.format('%1.2f',(v-32)*5/9)       -- a Fahrenheit-fokot átszámítjuk °C-ra
           elseif n == 'BoilingPtFH' then uto.BoilingPtCH = string.format('%1.2f',(v-32)*5/9)       -- a Fahrenheit-fokot átszámítjuk °C-ra
           elseif n == 'BoilingPtK'  then uto.BoilingPtC  = string.format('%1.2f',v-273.15)         -- a Kelvin-fokot átszámítjuk °C-ra
           elseif n == 'BoilingPtKH' then uto.BoilingPtCH = string.format('%1.2f',v-273.15)         -- a Kelvin-fokot átszámítjuk °C-ra
           end 
    end 
end


local function rendez(x,y)
  if x[1] == 'C' then return true; end
  if y[1] == 'C' then return false; end
  if x[1] == 'H' then return true; end
  if y[1] == 'H' then return false; end
  return x[1] < y[1]
end


local eredm    = {}    -- { címke, érték } rendezve

function menet2(hivo)
    local MolarMass = { 3, "[[Moláris tömeg]]" }
    local MeltingPt = { 8, "[[Olvadáspont]]" }
    local BoilingPt = { 9, "[[Forrás (átalakulás)|Forráspont]]" }
    local okepl = ''
    local molsuly  = 0
    
    for _, ertek in ipairs(molekula) do
        okepl = okepl .. ertek[1] .. '<sub>' .. ertek[2] .. '</sub>'
    end
    table.insert(munka, {{0, "'''TESZT'''"}, okepl})
    
    if not uto.Formula and #okepl > 0    -- saját összegképlet kiírása
    then       if uto.charge then str = '<sup>'..uto.charge..'</sup>' else str = '' end
               table.insert(munka,{boxtbl['Formula'],okepl..str})
    end
    if uto.MolarMass   -- megadta-e az molsúlyt
    then       table.insert(munka,{MolarMass,uto.MolarMass..nilstr(uto.MolarMass_notes)})   -- az ő molsúlya megjegyzéssel együtt
    else       if molsuly > 0      -- saját molsúly kiírása
               then table.insert(munka,{MolarMass,tohuszam(string.format('%1.'..uto.MassRound..'f',molsuly))..'&nbsp;g/mol'}) 
               end
    end
--  Olvadáspont
    str = ''
    if uto.MeltingPt       -- szöveggel megadott olvadáspont
    then   str = uto.MeltingPt
    elseif uto.MeltingPtC  -- °C-ban megadott olvadáspont
    then   str = tohuszam(uto.MeltingPtC)
           if uto.MeltingPtCH then str = str..'–'..tohuszam(uto.MeltingPtCH) end
           str = str..'&nbsp;°C'
    end
    if #str > 0 and uto.Melting_notes
    then   if hivo == 'Chembox_new' or hivo == 'Chembox_új'
           then   str = str..' ('..uto.Melting_notes..')'
           else   str = str..' '..uto.Melting_notes
           end
    end
    if #str > 0 then table.insert(munka,{MeltingPt,str}) end
--  Forráspont
    str = ''
    if uto.BoilingPt       -- szöveggel megadott forráspont
    then   str = uto.BoilingPt
    elseif uto.BoilingPtC  -- °C-ban megadott forráspont
    then   str = tohuszam(uto.BoilingPtC)
           if uto.BoilingPtCH then str = str..'–'..tohuszam(uto.BoilingPtCH) end
           str = str..'&nbsp;°C'
    end
    if #str > 0 and uto.Boiling_notes
    then   if hivo == 'Chembox_new' or hivo == 'Chembox_új'
           then   str = str..' ('..uto.Boiling_notes..')'
           else   str = str..' '..uto.Boiling_notes
           end
    end
    if #str > 0 then table.insert(munka,{BoilingPt,str}) end
--  Oldószerek
    if uto.SolubleOther
    then   if uto.Solvent  
           then table.insert(munka,{ {12,'[[Oldhatóság]] ('..uto.Solvent..')'},uto.SolubleOther})
           else table.insert(munka,{ {12,'[[Oldhatóság]]'},uto.SolubleOther})
           end
    end
    if uto.Solubility1  and uto.Solvent1 then table.insert(munka,{ {13,'[[Oldhatóság]] ('..uto.Solvent1..')'},uto.Solubility1}) end
    if uto.Solubility2  and uto.Solvent2 then table.insert(munka,{ {14,'[[Oldhatóság]] ('..uto.Solvent2..')'},uto.Solubility2}) end
    if uto.Solubility3  and uto.Solvent3 then table.insert(munka,{ {15,'[[Oldhatóság]] ('..uto.Solvent3..')'},uto.Solubility3}) end
    if uto.Solubility4  and uto.Solvent4 then table.insert(munka,{ {16,'[[Oldhatóság]] ('..uto.Solvent4..')'},uto.Solubility4}) end
    if uto.Solubility5  and uto.Solvent5 then table.insert(munka,{ {17,'[[Oldhatóság]] ('..uto.Solvent5..')'},uto.Solubility5}) end
    if uto.SolubilityProduct and uto.SolubilityProductAs 
    then table.insert(munka,{ {18,"[[Oldhatósági szorzat]], ''K''<sub>sp</sub> of "..uto.SolubilityProductAs},uto.SolubilityProduct})
    end
end

-- A munka-beli értékek rendezése és kiírása
local function rendez(hivo)
    if next(munka)
    then    -- van megadott paraméter
          local kozos = require("Module:Kembox/kozos")
          eredm[1] = csopfej
          kozos.adatcsoport(munka,eredm)       -- munka rendezése és átmásolása eredm-be
          return kozos.kiir(eredm,hivo)
    end
return ""
end

-- Kívülről is hívható függvények
local p = {}

-- Hívás sablonból
function p.Chembox_Properties(frame)
    local hivo  = frame.args['infobox']   -- hívó sablon
    local szulo = frame:getParent()       -- a chembox_related sablon által kapott paraméterek

    for nev,ertek in szulo:argumentPairs()
    do    egysor(nev,ertek)
    end
    menet2(hivo)
    return rendez(hivo)
end


-- Hívás modulból
function p.lua(partbl,hivo)
    for nev,ertek in pairs(partbl)
    do    egysor(nev,ertek)
    end
    menet2(hivo)
    return rendez(hivo)
end

return p;