Giter Site home page Giter Site logo

tancy1 / elementslib Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 457 KB

Lua module to interact with the periodic table

License: GNU Lesser General Public License v3.0

Lua 100.00%
lua lua-5-4 lua-module lua54 chemistry periodic-table periodic-table-of-elements utility

elementslib's Introduction

ElementsLib


This is a lua module to use the Periodic Table

Usage

Method Description
locate(I,W,O) I: Type of element to be searched
W: Element to be searched
O: Property to return
table List of all elements in the periodic table and their attributes
mass(...) Accepts any number of tables with the first value being Symbol of Element and the second being the number of particles
Compound:new(t) Makes new Compound.
t is a table contaning tables in the format of {Element=Number of Elements}
Compound.mass Mass of Compound
Compound:percentageByMass(Element) Returns percentage by mass
Compund:getAmount(args) parameter return specifies property to return grams or moles and other parameter is given property
mergeCompound(...) Merges any number of Compounds and returns 1 Compound
Compound:merge(Compound) Merges self with a compound then returns it
Compound:ef() Returns empirical formula of compound
Compound:string() Returns string of value
idealgaslaw(args) Table with values for temperature in kelvin, pressure in pascals, volume in cubic metres and amount of substance in mols
Output can be any of these values

Example

--Example
local Elements=require("Elements")
--prints the symbol for Silver
print(Elements.locate("Name","Silver","Symbol"))
-- returns Ag
print(Elements.mass({"H",2},{"O"}))
-- prints 18.015
water=Elements.Compound:new{{"H",2},{"O"}}
-- makes new compound
print(water.mass)
-- prints 18.015
print(water:percentageByMass("H"))
-- prints 0.11190674437968
print(water:getAmount{grams="36.03",returnValue="moles"})
-- prints 2.0
MgO=Elements.Compound:new{"Mg","O"}
CO2=Elements.Compound:new({"C",{"O",2}})
MgCO3=Elements.mergeCompound(MgO,CO2)
print(MgCO3.mass)
-- prints 84.313
MgCO3=MgO:merge(CO2)
print(MgCO3.mass)
-- prints 84.313
Nicotine=Elements.Compound:new{{"C",10},{"H",14},{"N",2}}
print(Nicotine:ef())
-- returns table in the form {{"C",5},{"H",7},{"N",1}}
print(water:string())
-- returns H20
print(Elements.idealgaslaw{mols=1,temperature="273.15",pressure=100000,output="volume"})
-- returns 0.002271095641486

elementslib's People

Contributors

tancy1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.