Parser

From NMReDATA
Revision as of 10:56, 2 May 2019 by Admin (talk | contribs) (Read the NMREDATA tags)
Jump to: navigation, search

Reading the SDF file

Libraries for divers languages exist to read SDF files. This section 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 writers 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 if needed (see possible object structure of NMReDATA).

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 tags (see below). 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
    • For version 1: ASCII 10

Analyse directly the tag (hopen there is no missing/spourious ASCII 10 in the text)

    • For version >1: "\" + ASCII 10

Before analysing the text of the TAG, ignore ASCII 10 and replace "\" with ASCII 10.

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. They can be directly used as name and value of object properties. The value should be read as text , because they have to be revritten later when writing the .sdf file ...

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).

IMPORTANT: Note that a property may appear more than once. In this case, it should be read into an array (and be written in the same order when writing the file).

The "Item from a list" have a format that depends on the tag. We have four types of tags:

  • NMREDATA_ASSIGNMENT
  • NMREDATA_J
  • NMREDATA_1D_ ...
  • NMREDATA_2D_ ...

For NMREDATA_1D_ and NMREDATA_2D_ see 1D_attributes and 2D_attributes.

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

This allows to have a single functions reading many types of tags.

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 written later.

Labels

Keep it mind the possibility that labels are put in <""> and the assignment may be vague!