Skip to content

A Groovy library with DSL for computing atomic weights of compounds (and %s of elements)

License

Notifications You must be signed in to change notification settings

adamldavis/groovy-chemistry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

groovy-chemistry

A Groovy library with DSL for computing atomic weights of compounds.

Call Chemistry.calc with a Closure. Chemistry uses propertyMissing to create either Element or Compound objects.

A Compound is composed of elements. Compound.elements returns a Map of Element to Integer (the number of the given element in the compound):

H2O.elements

The weight property gives the atomic weight of an element or compound:

H.weight

You can add and subtract elements and compounds:

H2O + Na2 - O

You can also multiply compounds by numbers:

(Ca3+(PO4)*2).weight

Use % (mod) to determine the percentage by atomic weight of an element in a given compound:

println "%Oxygen of Fe(NO3)3 = ${(Fe&(NO3)*3) % O}"

Use / (divide) to determine the number of an element in a given compound:

println "#Oxygen in Fe(NO3)3 = ${(Fe&(NO3)*3) / O}"

About

A Groovy library with DSL for computing atomic weights of compounds (and %s of elements)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages