Difference between revisions of "Parser"

From NMReDATA
Jump to: navigation, search
Line 1: Line 1:
Possible structure of the object including NMReDATA reflecting the format of NMReDATA tags of SDF files.
 
 
'''Note:''' This is not designed to include ambiguities in the assignment. This is therefore only for use with Level=0.
 
  
 
=== Reading the SDF file ===
 
=== Reading the SDF file ===
Line 24: Line 21:
 
Read the NMReDATA tag. Keep in mind the [[end-of-line | end of line problem ]].
 
Read the NMReDATA tag. Keep in mind the [[end-of-line | end of line problem ]].
  
First read and analyse the NMREDATA_VERSION to  
+
First read and analyse the NMREDATA_VERSION to  
 
* determine what character should be ignored (ASCII 10, except for version 1)  
 
* determine what character should be ignored (ASCII 10, except for version 1)  
 
* determine the line separator ("\", except for version 1, in which cas the ASCII 10 is the line separator)  
 
* determine the line separator ("\", except for version 1, in which cas the ASCII 10 is the line separator)  
  
=== read the NMREDATA tags ===
+
=== Read the NMREDATA tags ===
  
 
Many simple tags have no particular format. (NMREDATA_SOLVENT, NMREDATA_VERSION, etc.)  
 
Many simple tags have no particular format. (NMREDATA_SOLVENT, NMREDATA_VERSION, etc.)  
Line 35: Line 32:
  
 
Two type of lines should be distinguished:
 
Two type of lines should be distinguished:
* property lines
+
* Property lines
* item in a list
+
* Item from a list
  
 
The "property lines" contain a serie of characters (letters) followed the "=" sign followed by the value of the variable.
 
The "property lines" contain a serie of characters (letters) followed the "=" sign followed by the value of the variable.
  
The "property lines" contain should be identified as such. Property lines should be before the list, but some may follow the lost (not recommended, but possible).
+
The "property lines" should be identified as such to distinguish them from element of a list. Property lines should be located before the list, but some may follow the list (not recommended, but possible).
  
 
Note that a property may appear more than once.
 
Note that a property may appear more than once.
Excample:
+
Example:
  
 
  Author=John
 
  Author=John
Line 51: Line 48:
  
 
We recommend the first store the list as an array of array of characters, only later analyse it.
 
We recommend the first store the list as an array of array of characters, only later analyse it.
See [[nmredata object structure|possible object structure of NMReDATA]] for more details.
+
 
 +
=== Analyse the individual NMR tag ===
 +
 
 +
Depending on the program, what data will be extracted will vary, but all Properties (whether they are understood or not) should be send to the output when writing the file. They don't need to be analysed.
 +
Same argument for the properties of peaks. They should all be stored (even if not understood) to be writting later.

Revision as of 07:56, 29 January 2019

Reading the SDF file

Libraries for divers languages exist to read SDF files. This paragraph is only relevant if you write your own reader/writer

We recommend having in mind, when reading, that an SDF file will have to be written at some point later. We recommend to write TAGS them in the same oder, but don't expect all reader to do so, so be ready for the TAGS to appear in any order.

If not too large, the content of the input should be kept in memory so that it can be written later. Since SDF files may contain divers TAGS (not only the NMREDATA tags) they should all be written in the output SDF file.

We recommend to

  • Open the SDF file
  • Read/store the molblock as chain of characters
  • Read/store the TAGS as chain of characters
  • Close the file
  • Analyses/check the molblock (see possible object structure of NMReDATA). Be

Determine how to read the NMREDATA tags

Scan the tags and list the index of the ones including NMREDATA_ in their name

Read the NMReDATA tag. Keep in mind the end of line problem .

First read and analyse the NMREDATA_VERSION to

  • determine what character should be ignored (ASCII 10, except for version 1)
  • determine the line separator ("\", except for version 1, in which cas the ASCII 10 is the line separator)

Read the NMREDATA tags

Many simple tags have no particular format. (NMREDATA_SOLVENT, NMREDATA_VERSION, etc.)

But most "complex" tags (NMREDATAT_ASSIGNMENT, NMREDATA_J, NMREDATA_1H, etc.) all have a common general structure:

Two type of lines should be distinguished:

  • Property lines
  • Item from a list

The "property lines" contain a serie of characters (letters) followed the "=" sign followed by the value of the variable.

The "property lines" should be identified as such to distinguish them from element of a list. Property lines should be located before the list, but some may follow the list (not recommended, but possible).

Note that a property may appear more than once. Example:

Author=John
Author=Paul

In this case it should be stored as an array.

We recommend the first store the list as an array of array of characters, only later analyse it.

Analyse the individual NMR tag

Depending on the program, what data will be extracted will vary, but all Properties (whether they are understood or not) should be send to the output when writing the file. They don't need to be analysed. Same argument for the properties of peaks. They should all be stored (even if not understood) to be writting later.