Skip to content
Chemical Structure Builder with Swift & iOS ⚛️🧪
Swift Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example
Heisenberg
Sources
.gitignore
.travis.yml
Heisenberg.podspec
LICENSE
README.md
_Pods.xcodeproj

README.md

Heisenberg

Heisenberg

CI Status Version License Platform

Heisenberg is an iOS UI library for creating / using chemical structures with written in Swift. It represent directional structures as using HeisenbergDirectionalStructure and just linear structures as using HeisenbergLinearStructure. You can change bonds between two elements as SingleBond, DoubleBond or TripleBond

HeisenbergDirectionalStructure is based on Graphand HeisenbergLinearStructure is based on SinglyLinkedList . You can create just x-axis linear structure with HeisenbergLinearStructure but with HeisenbergDirectionalStructure you can create / build what a Graph can do it.

HeisenbergLinearStructure

let heisenberg = HeisenbergLinearStructure(with: hidyrogen1, itemSize: 40)
heisenberg.linkTo(with: oxgen, with: .SingleBond) { (structure) in
    // structure callback
}.linkTo(with: hidyrogen2, with: .TripleBond) { (structure) in
       
}.linkTo(with: tAtom, with: .TripleBond) { (structure) in
   
}.linkTo(with: babyAtom, with: .TripleBond) { (structure) in

}
let board = HeisenbergBoard<String>(with: heisenberg, with: .cyan)
let boardView =  board.drawBoard()
view.addSubview(boardView)

Linear Structure

HeisenbergDirectionalStructure

let directional = HeisenbergDirectionalStructure(with: cAtom, itemSize: 50)
directional.linkWith(from: cAtom, to: nAtom, way: .next, bond: .SingleBond, bondColor: .black) { (structure) in

}.linkWith(from: nAtom, to: h1Atom, way: .crossUpForward, bond: .SingleBond, bondColor: .black) { (structure) in

}.linkWith(from: nAtom, to: h3Atom, way: .crossDownForward, bond: .SingleBond, bondColor: .black) { (structure) in

}.linkWith(from: nAtom, to: h2Atom, way: .next, bond: .SingleBond, bondColor: .black) { (structure) in

}.linkWith(from: cAtom, to: loveAtom, way: .downward, bond: .TripleBond, bondColor: .darkGray) { (structure) in

}

let board = HeisenbergBoard<String>(with: directional, with: .lightGray)
let boardView = board.drawBoard()
view.addSubview(boardView)

CH4 Directional

Directional Directional

Directional Directional

Bonding Between Atoms

You can tie two or more atoms with elements bonds. There's a list for bond way.

public enum StructuralWay: String{
    case upward = "up"
    case downward = "down"
    case next = "next"
    case angular = "angular"
    case crossDownForward = "cross_down_forward"
    case crossUpForward = "cross_up_forward"
    case crossDownBackward = "cross_back_down"
    case crossUpBackward = "cross_back_up"
}

HeisenbergBoard

HeisenbergBoard is a class for creating board to handle UI structure of chemical structures. You can pass any HeisenbergLinearStructure or HeisenbergDirectionalStructure and you must select a backgroundColor of the board. Then method drawBoard() returns a UIView for your structure.

let board = HeisenbergBoard<String>(with: directional, with: .lightGray)
let boardView = board.drawBoard()

Example

I've added bunch of test functions to generate a Heisenberg. You can check it out. To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

Heisenberg is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Heisenberg'

Author

eliakorkmaz, emrahkrkmz1@gmail.com

License

Heisenberg is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.