0 Members and 1 Guest are viewing this topic.
ok. I'll see what I can do. Question. For "atomic number", can't I just use the number of valence electrons? I think that, when it comes to drawing Lewis Structures, only the valance orbital is what affects bonding.
I may need help with rendering the final object to the screen.
Also, how do you determine what molecules make up the main chain, and what molecules go around the main chain?
Quote from: ACagliano on October 29, 2011, 10:54:02 amok. I'll see what I can do. Question. For "atomic number", can't I just use the number of valence electrons? I think that, when it comes to drawing Lewis Structures, only the valance orbital is what affects bonding.Well, yeah, you could do that, but then you wouldn't know what letter to display . It depends how far you want this program to go, but you might have to look farther than valence electrons if you are going to handle expanded octets.QuoteI may need help with rendering the final object to the screen.OkQuoteAlso, how do you determine what molecules make up the main chain, and what molecules go around the main chain?That is where the real challenge comes in. For inorganic stuff, you might almost need to have a database of polyatomic ions. For your purposes, you probably shouldn't end up having more than 50. If you don't want to do that You could also try to determine the structure of the polyatomic ion by comparing the number of valance electrons of each atom along with how many of each atom is present. Typically, the element with the most atoms will be the outer atoms with oxygen almost always being an outside atom. (I can think of a few weird ones, CN-, SCN-, and OCl-. Also, stuff like NO3- has a double bond in it.)For organic materials, once you figure out a system, it shouldn't really be that hard. Just try to determine what structures are side chains and what are main chains and you should be ok. If you really love chemistry, you could try to parse IUPAC names, but that would be tough.
2. Scrolling is a bit harder, any way you do it it's going to be messy. I have two approaches, the oversized buffer method, and the clipping method. Oversized buffer: For this, you'll want to allocate a big buffer, 150x150 pixels should be fine. Then, you'll have to make your own drawing methods to draw to this buffer. You really only have to copy over a line drawer and a vPutS, which isn't really that tough. After that, you simply draw you whole molecule to the buffer and only display the 96x64 region that is currently showing. Clipping method: This method might be harder, but it uses fewer resources. You will probably be able to use the system vPutS for this but you'll need a special line routine that automatically clips itself to the edges of the screen. (badja made one). From here, you also need to define how far the screen has scrolled from the top left corner of the true screen. The final step is just to take the coordinates of something on the screen, subtract from it how much the screen has shifted, and draw the atom to the resulting position on the screen. You'll just have to watch out to make sure that you don't accidentally try to vPutS something off the screen.
Quote from: thepenguin77 on October 28, 2011, 11:20:41 pm2. Scrolling is a bit harder, any way you do it it's going to be messy. I have two approaches, the oversized buffer method, and the clipping method. Oversized buffer: For this, you'll want to allocate a big buffer, 150x150 pixels should be fine. Then, you'll have to make your own drawing methods to draw to this buffer. You really only have to copy over a line drawer and a vPutS, which isn't really that tough. After that, you simply draw you whole molecule to the buffer and only display the 96x64 region that is currently showing. Clipping method: This method might be harder, but it uses fewer resources. You will probably be able to use the system vPutS for this but you'll need a special line routine that automatically clips itself to the edges of the screen. (badja made one). From here, you also need to define how far the screen has scrolled from the top left corner of the true screen. The final step is just to take the coordinates of something on the screen, subtract from it how much the screen has shifted, and draw the atom to the resulting position on the screen. You'll just have to watch out to make sure that you don't accidentally try to vPutS something off the screen.I would highly recommend not going with the virtual buffer method. As you mentioned, it's messy. It's also rather inefficient for long carbon/Silicon chains where you have large 2d plots, but relatively few molecules. I'd instead recommend a more "vector"-ish approach where the coordinates of the nuclear centers are represented in a virtual 3d space as a table of coordinates and bond relations. When you need to display them, you define a 2d buffer that will be directly translated to the screen and just project the points from that 3d space into the buffer along with the bonds. A bit more complex, perhaps, but it allows "infinite resolution" of arbitrarily large molecules (within reason of course) and uses a less memory for molecules with low nuclear density since all you're storing is an extra coordinate over the 2d buffer method.As for generating the structures themselves from the formulas, I'll be blunt. It's basically impossible to do at any significant level of accuracy, since the structure of a molecule depends on a lot more than just an enumeration of the atoms in it. For example, it often depends on the prior history of its constituent atoms. A good demonstration of this is Barrelene, a molecule with the formula C8H8. This molecular formula is also shared by Cubane and Styrene, among a few others. These isomers are all [somewhat] stable in their radically different configurations and determining which one the user means is nigh impossible. A structural formula like SMILES is much less ambiguous, pretty widely available for most molecules, and essentially eliminates the near impossible problem of predicting molecular structure.
[Atomic number][lone pairs][charge][flags xx112234][bonded id 1][bonded id 2][bonded id 3][bonded id 4][bonded id 5][bonded id 6][display x][display y]Where: - atomic number = atomic number - lone pairs = number of lone pairs - charge = formal charge - flags = bond type 0 = single bond, 1 = double bond, 2 = triple bond, 3 = ionic - bonded id # = the array position of the other atom it is bonded to - display x/y = where it is displayed on the full bufferSo with this system, you have the 10 byte atom structures lined up in memory. Each one would have an ID based on where it is in memory as well as the atoms it is bonded to. The goal would then be to parse what the user typed and turn it into one of these structures. If you start to get triple bonds, you may have to switch some of the bond id's around as you add them, but that is fine.Using this system, you should be able to represent any kind of atom I can think of, even complex organic molecules.
One problem...the flags. A flag can only be 0 or 1, but i'd also need 2 or 3 as a value. How is that gonna happen?
No, 6 is the max, as long as you don't go into crazy stuff which I'm not even sure is possible. (6 atoms involves hybridizing the s, p, and d orbitals, to do 8, you might have to start messing with the f orbital.) Also, you have to remember that atoms share electrons, so, for normal cases, you'll only have 4 atoms bonded.You could do 2 bytes for flags, but to be honest, I don't think you'll ever run into a situation where you'll need 5 and 6 to have flags. Atoms can normally only have 4 bonds, so that is not a problem. The only time you start messing with the 5th and 6th atoms are when you go into expanded octets. The only possible way that your 5th atom could have a flag would be if it were double bonded, and I'm not sure this ever happens. You would have something along the lines of SF4O, which is not a real compound, and the O would be double bonded to the S. I don't think this is something you need to worry about though.I don't think you understand what I meant by the ID. Lets say we're doing KNO3: Here's what your full data set would look like.1. K [19][0][+1][11 00 00 00][2][0][0][0][0][0]2. O [8][3][-1][11 00 00 00][1][3][0][0][0][0]3. N [7][0][+1][01 00 00 00][4][2][5][0][0][0]4. O [8][2][0][01 00 00 00][3][0][0][0][0][0]5. O [8][3][-1][00 00 00 00][3][0][0][0][0][0]The ID's are essentially pointers to the data. The only thing that makes it nicer is that it is 1 byte rather than two. Of course, you could do addresses if you really wanted, it would just take up more space.Pointing to a polyatomic isn't a bad idea actually. Though, you'd save yourself a headache if you manage to parse the polyatomics on the fly. The only problem with pointing to polyatomics would be difficulties with drawing them. You'd have to special case them because you'd have a single polyatomic ion that might be bonded to multiple things. Cu(OH)2.