How to store molecules in memory?
Methane (CH4) C-H bond-length: 108.7 pm H-H angle: 109 degrees
But also more complex molecules, like paracetamol (C8H9NO2):
How can I store molecules in memory, including all bond-lengths and angles?
A good idea to store atom-structs in an array? Or is there a better way?
- Declaring instance variables in iOS - Objective-C
- Global variables in Objective-C - difference in extern and top of .m file declaration
- Passing dynamic Int variable from one class to another class in Swift
- In Objective-C, are int variables that haven't been assigned a value nil?
- Where various variable and method types should be placed in a header
- Use NSString variable created in viewDidLoad inside another method
5 Solutions Collect From Internet About “How to store molecules in memory?”
It looks like some kind of graph data structure:
- A molecule has a set of atoms
- Atoms are linked by bonds:
- A bond can be double, single or tripple
- A bond has a length
- A bond has an angle
- It’s a cyclic graph (for instance, the example in the question has a ring of alternating single and double bonds)
- It’s not a directed graph (if two atoms are bonded, it doesn’t matter from which end you approach the bond)
Typically you’d store a graph as an array of nodes (atoms) and an array of edges (bonds). Nodes and edges would both be pointers to structs.
A node (atom) would store the element.
An edge (bond) would store the following fields:
- A pair of pointers to nodes
- The type of bond (double/single)
- The bond length and angle
Since it’s not a directed graph, your data structure would consider an edge between A and B to be equivalent to an edge between B and A. That is, for a given pair of atoms, you’d expect your edge array to contain an edge from A to B and never from B to A.
Given that you’re modeling a linked structure, it seems like a linked data structure would be the most appropriate representation. I’m afraid I’m not enough of a chemist to guess at all the data that would be interesting to store for each item though.
Offhand, it sounds a lot like a very slightly modified version of how you usually store a graph though — nodes and links, with data associated with each. In a graph, the typical data associated with a link is the “cost” of that link, but in this case it sounds like you’d store a vector (angle and a length).
Maybe you should have a look at Molecules by Brad Larson, a supernice open source app for iPhone/iPod/iPad that inspired already many programmers. I guess he uses a standard data format for molecules that can inspire yours
Are you going to be doing any kind of computations on these molecules, or just drawing them? If you have any intention of doing any rigorous calculations, then I would not even try using Objective C. For best performance, you should store the angles, lengths, and connections in normal arrays, and do all the accounting necessary to keep track of what’s what. These types of applications that use fancy data structures and such to hold the molecule info run very poorly if there is a lot of computation involved as well.
A molecule in your posting is a descriptor like template of an instance of a concrete molecule (with different cartesian coordinates). Therefore, you need only one “molecule” for every possible number of molecule-type instances. Then, you need an array of coordinates from where you can extract which coordinates give one molecule. For this single descriptor, you should create data structures that allow you to access the values in the best way possible. Maybe a vector of (a,b,r,type)-Structs for bonds, a vector of (a,b,c,w,type) for angles etc.
- Swift closure as AnyObject
- What is the most efficient way to sort an NSSet?
- How do I get a UIButton press to work in a UICollectionViewCell in Swift?
- ios App – crash on multiple segue at the same time (going to other segue while one is animating)
- How can I add a watermark in a captured video on iOS
- Change the 'Gravity' on a UIScrollView with Paging
- Display Locations on UITableview
- Is there an SDK to draw lines on iOS with touch?
- iOS:How to open camera with animation effect?
- UIImageView Transform Scale
- Multiple Video, Same Screen
- Convert between UIImage and Base64 string
- Database is locked in Sqlite
- AFNetworking version 2 content-type error
- Programmatically add UINavigationController in UIViewController