madilynpaul / bondwalk

0 stars 0 forks source link

Bond order breaking valence. #1

Open madilynpaul opened 1 year ago

madilynpaul commented 1 year ago

Issue in Bond_Walking.ipynb. Trying to increase the bond order of certain bonds using the bond_walk function. If the current order is equal to the octet happy = True, but if it isn't happy should equal false. If happy = false for both the starting atom and the next atom I want it to increase the bond order of the bond between those atoms by 1. Right now it seems to be increasing the bond order of all the bonds connected to the starting atom.

erjank commented 1 year ago

First of all, need to add: compound = Molecule.from_file("ben.sdf",file_format = "sdf") before you call walk_molecule so that you're working with a fresh molecule each time. Next, add some logic to check if the current order is too high, low, or correct. Finally, walk out the steps by hand for what you want your code to do: Here we're expecting to draw two double bonds , but if we draw the first one between 0 and 1 that'll be incorrect, so we WANT our algorithm to try drawing that first bond, walk to the second carbon, see it's happy, walk to the third carbon, try drawing a bond to the sulfur, walk to the sulfur and then realize it's got too many, backtrack all the way to the first carbon, then try drawing a bond to the other carbon, and then walking the sufur, carbon (now drawing the last bond)... which means that our code still has a lot missing, we'll need to set visited=False when we backtrack, which we don't currently have, and will take some more thought!

madilynpaul commented 1 year ago

My latest commit got add_order to add to the bond between atom and next atom if atom had a current order < the octet, but I need to add a way to check the valence and back track if it breaks the octet rule.

Could we randomize the next_atom out of the bond list and have it just guess in adding double bonds between the ones with an unsatisfied octet until all the octets are happy? What if we used a while loop within the function to say "while happy == False, restart walk_bond"?

erjank commented 1 year ago

Great! There's a couple directions we might go:

Now that walk_molecule is getting a little big, it's a good hint that we can pull out some of its functionality and encapsulate that into other functions. For example, we might make a get_atom_info function that we pass an atom and bondlist to, receiving its bond order and the bond orders of its neighbors. It'll also make the code easier to read because the function calls in the body of walk_molecule will tell us what we want to have happen - it's kindof like self-documentation!

madilynpaul commented 1 year ago

I'm working on getting a few supporting functions up and running. The one that I'm working on now is a check octet function that feeds in the atom and the compound. I don't quite understand how the "happy" portion works. Is happy a list that correlates the atom index to whether happy is true or false?

madilynpaul commented 1 year ago

I'm also noticing that once we add the add_order that's determined by the check_octet function to the bond order, the bond order around the atom index 1 is reporting as 4, even though there's 5 bonds around it. I've been trying to figure out why this is, it might just be reporting before the walk function gets called again so it isn't adding the second increase in bond order, but I'm not quite sure.