Chemical Structure Builder with Swift & iOS
Heisenberg
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)
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)
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