Chemistry - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Chemistry

DescoladaDescolada Posts: 21Member
It's a long shot, but would anyone out there know how to write a program that can interpret chemical formulas? I am trying to make a computer program to convert chemical formulas to dot diagrams. Ive gotten it to be able to tell how many atoms of each element are in a reactant. The problem I'm struggling with is telling how they are bonded. I need to know which atom is bonded to which, not just how many there are. I can't seam to get it to work. For example: I enter in H2O, what it should show is both hydrogen atoms covalently bonded to the oxygen. Sometimes however the hydrogens diatomicly bond with each other, and leave a lone oxygen. How is the program supposed to know what to do? I accept that what I am trying to do could simply be impossible, if you think so too, or have any suggestions please tell.

Comments

  • zibadianzibadian Posts: 6,349Member
    : It's a long shot, but would anyone out there know how to write a program that can interpret chemical formulas? I am trying to make a computer program to convert chemical formulas to dot diagrams. I’ve gotten it to be able to tell how many atoms of each element are in a reactant. The problem I'm struggling with is telling how they are bonded. I need to know which atom is bonded to which, not just how many there are. I can't seam to get it to work. For example: I enter in H2O, what it should show is both hydrogen atoms covalently bonded to the oxygen. Sometimes however the hydrogens diatomicly bond with each other, and leave a lone oxygen. How is the program supposed to know what to do? I accept that what I am trying to do could simply be impossible, if you think so too, or have any suggestions please tell.
    :
    What you are trying to do is nearly impossible, but not impossible as such. The real problem lies in the fact that there are many structure for the same formula. Example: C6H12: cyclohexane, hexene, n-methyl-pentene, etc.
    If you just want to use simple structures (H2O, CO2, etc.), then it is very doable. It involves a few steps.
    - first you need to create a dbase of all possible combinations (H-H-O, H-O-H)
    - then you need to validate the number of bonds of each atom. Example:
    H1-H2-O1: H1 Valid, H2 Invalid, O1 Invalid
    H1-O1-H2: H1 Valid, O1 Valid, H2 Valid
    - if you don't get any valid combinations, start working on double & triple bonds:
    C-O-O, C=O-O, C-O=O, C=O=O, O-C-O, O=C-O, O-C=O: All invalid
    O=C=O: valid
    - Each valid combination should then be displayed.
    For these simple molecules, this system works. But for larger molecules you need to approach this more intelligently.
  • ManningManning Posts: 1,621Member
    : It's a long shot, but would anyone out there know how to write a program that can interpret chemical formulas? I am trying to make a computer program to convert chemical formulas to dot diagrams. Ive gotten it to be able to tell how many atoms of each element are in a reactant. The problem I'm struggling with is telling how they are bonded. I need to know which atom is bonded to which, not just how many there are. I can't seam to get it to work. For example: I enter in H2O, what it should show is both hydrogen atoms covalently bonded to the oxygen. Sometimes however the hydrogens diatomicly bond with each other, and leave a lone oxygen. How is the program supposed to know what to do? I accept that what I am trying to do could simply be impossible, if you think so too, or have any suggestions please tell.
    :

    I think you summed up your question pretty good with "How is the program supposed to know what to do?". The answer is, you have to tell it. Until we program computers that can go to school and learn on their own, they will only know as much about Chemistry as we tell them.

    You will have to tell your program that H2O can combine covalently or diatomically. So after you enter H2O it can prompt you with "Bonded (D)iatomically or (C)ovalently?" and it can display the appropriate diagram based on your input.
Sign In or Register to comment.