home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / apps / science / chempars / chempars.doc next >
Text File  |  1986-11-12  |  6KB  |  130 lines

  1.  
  2.  
  3.   CHEMPARSE - A Recursive Depth Parser for Organic Substructures
  4.  
  5.  
  6.      CHEMPARSE  is a program which interprets chemical  structures 
  7. and substructures you type by using a recursive descent parser.  A 
  8. RDP  parser  is a good way to handle input that can  be  described 
  9. using a context-free grammar.   A grammar in computer science is a 
  10. set  of  rules that can be used to tell whether a given  input  is 
  11. valid  -  sort  of  the same idea as  English  grammar,  but  more 
  12. rigorously  defined.   A  context-free grammar is one  where  each 
  13. "phrase" (called a non-terminal) can be expanded the same way into 
  14. the final "words" (called terminals), regardless of its location.
  15.      Pascal  and LISP are examples of computer languages that  can 
  16. be  descibed with context-free grammars.   The rules for what  you 
  17. can  put  inside a BEGIN..END block are the  same,  regardless  of 
  18. whether  it's part of a IF x THEN BEGIN..END statement,  a WHILE x 
  19. DO BEGIN..END statement,  or the main block of a program.  English 
  20. is not a context-free grammar.
  21.      Bachus-Naur formalism is a good way to describe the rules  of 
  22. a  context-free  grammar.   For each non-terminal,  a BNF sentence 
  23. describes how it can be expanded.  Some examples from Pascal are:
  24.  
  25. IF-THEN-statement ::= "IF" logical-expression "THEN" statement.
  26. statement  ::= BEGIN-END-block | IF-THEN-statement  |  assignment-
  27. statment | other-statments | empty-statement.
  28. BEGIN-END-block ::= "BEGIN" statement { ";" statement } "END".
  29.  
  30.      The symbols used in BNF are:
  31.  
  32. ::=       "is defined as"
  33. |         "or"
  34. { x }     x may be present 0, 1, or more times
  35. [ x ]     x may be present 0 or 1 times but not more
  36.  
  37.      The non-terminals are IF-THEN-statement,  logical-expression, 
  38. statement,     BEGIN-END-block,    assignment-statement,    other-
  39. statements,  and  empty-statement.   The  terminals are IF,  THEN, 
  40. BEGIN,  END and ;.   You might notice that BEGIN-END-block is used 
  41. to define STATEMENT and STATEMENT in turn is used to define BEGIN-
  42. END-block.   Although  not done here,  it's also possible to use a 
  43. non-terminal in its own definition.  One example might be:
  44.  
  45. integer ::= digit [ integer ].
  46. digit  ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |  "8"  | 
  47. "9".
  48.  
  49.      A RDP works by calling a separate parsing routine for each of 
  50. the  BNF  sentences.   If non-terminals are found,  their  parsing 
  51. routines are called until eventually the system works its way down 
  52. to  only  terminals.   RDP's are thus highly recursive (hence  the 
  53. name),  and  are best written in languages such as Pascal and LISP 
  54. which handle recursion easily.
  55.      Context-free grammars and RDP can be used for more than  just 
  56. describing  computer languages.   Chemical structures can also  be 
  57. described  in a linear notation using context-free grammar.   This 
  58. linear  notation  has long been a convenient way for  chemists  to 
  59. describe a structure in text.  Some examples are:
  60.  
  61. Ethanol (ethyl alcohol)       CH3-CH2-OH 
  62. Ethyl acetate                 CH3-C(=O)-O-CH2-CH3
  63. t-Butyl amine                 NH2-C(CH3)(CH3)CH3
  64.  
  65. Single  bonds  are represented with a dash,  double bonds with  an 
  66. equal  sign.   Branching  is handled by placing the branch  inside 
  67. parentheses.
  68.      We  have  been  using this notation at  the  CASE  (Computer-
  69. Assisted  Structure Elucidation) lab at the chemistry  departement 
  70. of  Arizona State University to enter structure  and  substructure 
  71. information   (it's   a  lot  cheaper  than  buying   a   graphics 
  72. workstation!).   We  have expanded the symbols used to allow for a 
  73. wider   variety  of  structures  and  the  limitations  of   ASCII 
  74. characters.  Triple bonds are represented with a plus sign.  Bonds 
  75. not  explicitly  shown may be any type (except bonds  to  hydrogen 
  76. atoms,  which are always single and never shown).  A decimal point 
  77. may be used to explicily show an undefined bond.   Rings are shown 
  78. by  "labeling"  one  atom and then connecting to  the  label  from 
  79. another  atom.   Disjoint (in two or more fragments) substructures 
  80. are  entered by separating each fragment with a  semicolon.   Some 
  81. more examples:
  82.  
  83. Acetonitile                   CH3-C+N
  84. Cyclopropane                  1:CH2-CH2-CH2-1
  85. Benzene                       1:CH=CH-CH=CH-CH=CH-1
  86. Two ethyl groups              CH3-CH2;CH3-CH2
  87. Any nitrogen-oxygen bond      NO or N.O
  88.  
  89.      We  are currently using a RDP for this notation with  several 
  90. applications.  The BNF is:
  91.  
  92. (Sub)structure ::= fragment [ ";" (sub)structure ].
  93. fragment ::= atom-group [ branch ] [ bond fragment ].
  94. branch ::= "(" bond fragment ")" [ branch ].
  95. bond ::= [ "-" | "=" | "+" | "." ].
  96. atom-group ::= digit | ( [ digit ":" ] atom [ "H" num-of-H ] ).
  97. atom ::= "C" | "N" | "O" | "S" | "F" | "CL" | "BR" | "I" | "NO2" | 
  98. "A".
  99. digit ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9".
  100. num-of-H ::= { "0" | "1" | "2" | "3" }.
  101.  
  102.      The  CHEMPARS  program reads a line of up to  60  characters, 
  103. sends  it  to the RDP routine,  and produces a table  listing  the 
  104. non-hydrogen  atoms,  their connections,  and possible atom types.  
  105. Entering "Q" quits the program.   If you have a color monitor,  be 
  106. sure to run it in medium resolution.   The  source code is written 
  107. in O.S.S.  Personal Pascal.   The procedures which parse each non-
  108. terminal are:
  109.  
  110. Non-terminal                  Procedure
  111. ------------                  ---------
  112. (sub)structure                P_SUBSTR
  113. fragment                      P_FRAG
  114. branch                        P_PAREN
  115. bond                          P_BOND
  116. atom-group                    P_ELG
  117. atom                          P_ATOM
  118. digit                         (handled in-line)
  119. num-of-H                      P_NUMHS
  120.  
  121.      Much  of  the above text is a result of  discussions  between 
  122. myself and Chris Chabris,  who greatly clarified my muddy concepts 
  123. and  pointed  out  the relationships between BNF,  CFG,  and  RDP.  
  124. Thanks, Chris.
  125.  
  126.                               -- Brad Christie  76167,1461
  127.  
  128.  
  129.  
  130.