Skip to content

JSON Structure format (Principles)

AlexanderSavelyev edited this page Jan 26, 2021 · 1 revision

Overview

Background

General scheme

Everything is a graph. Nodes and Edges which can have types

SD file

Reaction

JSON Schemes

Root Scheme

{
   id: '/Graph',
   type: 'object',
   required: ['root'],
   properties: {
      root: { $ref: '#/root' }
   },
   patternProperties: {
      '^mol': { $ref: '/Molecule' },
      '^rg': { $ref: '/RGroup' }
   },
 
   root: rootSchema
}
  
const rootSchema = {
   id: '/Root',
   required: ['nodes'],
   properties: {
      nodes: {
         type: 'array',
         items: {
            oneOf: [
               { $ref: '/RxnPlus' },
               { $ref: '/RxnArrow' },
               {
                  type: 'object',
                  required: ['$ref'],
                  properties: {
                     $ref: {
                        type: 'string'
                     }
                  }
               }
            ]
         }
      },
      edges: {
         type: 'array',
         items: {
            oneOf: [
               {
                  properties: {
                     $refs: {
                        type: 'array',
                        maxItems: 2,
                        items: {
                           type: 'string'
                        }
                     }
                  }
               }
               // ...
            ]
         }
      }
   }
};

Molecule Schema

{
   id: '/Molecule',
   type: 'object',
   allOf: [
      { $ref: '#/header' },
      {
         properties: {
            atoms: {
               title: 'Atoms',
               type: 'array',
               items: {
                  oneOf: [
                     { $ref: '#/atom' },
                     { $ref: '#/rgatom' },
                     { $ref: '#/atomlist' }
                  ]
               }
            },
            bonds: {
               title: 'Bonds',
               type: 'array',
               items: { $ref: '#/bond' }
            },
            sgroups: {
               title: 'SGroups',
               type: 'array',
               items: { $ref: '#/sgroup' }
            }
         }
      }
   ],
 
   header,
   atom,
   atomlist,
   rgatom,
   bond,
   sgroup
}

RGroup Schema

{
   id: '/RGroup',
   type: 'object',
   allOf: [
      {
         properties: {
            rlogic: { $ref: '#/logic' }
         }
      },
      { $ref: '/Molecule' }
   ],
 
   logic: rgroupLogic
}
  
const rgroupLogic = {
   title: "RGroupLogic",
   type: "object",
   required: ['number'],
   properties: {
      number: {
         type: 'number'
      },
      range: {
         title: 'Occurrence',
         type: 'string',
         maxLength: 50,
         default: ''
      },
      resth: {
         title: 'RestH',
         type: 'boolean',
         default: false
      },
      ifthen: {
         title: 'Condition',
         type: 'integer',
         minimum: 0,
         default: 0
      }
   }
};

Examples

Simple molecule

{
    "root" : {
        "id" : "",
        "type" : "molecule",
        "atoms" : [
            {"id": "a1", "label" : "C", "location": [ -0.762160, 1.168557, 0.022754 ]},
            {"id": "a2", "label" : "C", "location": [ 0.631044, 1.242862, -0.013022 ]},
            {"id": "a3", "label" : "N", "location": [ 0.631044, 1.242862, -0.013022 ]}
        ],
        "bonds" : [
            { "atoms" : ["a1", "a2"], "order" : 1 },
            { "atoms" : ["a2", "a3"], "order" : 2 }
        ]
    }
}

Reaction

{
    "root" : {
        "id" : "",
        "type" : "graph",
        "nodes" : [
            {
                 "$ref": "mol1"
            },
            {
                 "$ref":"mol2"
            }
        ],
        "edges" : [
            {
                "refs" : ["mol1", "mol2"]
            }
        ]
    },
    // All graphs, types "graph", "atom", "bond". Will use the molecule instead of graph, but keep it here
    "mol1" : {
        "type" : "graph",
        "nodes" : [
            {"id": "a1", "type": "atom", "label" : "C", "location": [ -0.762160, 1.168557, 0.022754 ]},
            {"id": "a2", "type": "atom", "label" : "C", "location": [ 0.631044, 1.242862, -0.013022 ]}
        ],
        "edges" : [
            { "type": "bond", "refs" : ["a1", "a2"], "order" : 1 }
        ]
    }
    // Just a sugar for the first variant
    "mol2" : {
        "type" : "molecule",
        "atoms" : [
            { "id": "a1", "label" : "C", "location": [ -0.762160, 1.168557, 0.022754 ] },
            { "id": "a2", "label" : "C", "location": [ 0.631044, 1.242862, -0.013022 ] }
            { "type": "rg-label", "location": [ 1, 1, 1 ], "$refs": ["r1", ...], "rgroups": [{ /RGroup }, ...] }  // refs to RGroups in root OR inline RGroups
        ],
        "bonds" : [
            { "refs" : ["a1", "a2"], "order" : 1 }
        ]
    }
    "r1" : {
        "type" : "rgroup",
        "rlogic": {
           "ifthen":"r5"
           "number":4
           "range":">0"
        }
         "atoms" : [
            {"id": "a1", "label" : "C", "location": [ -0.762160, 1.168557, 0.022754 ]},
 
    }
}

SD File

{
    "root" : {
        "id" : "",
        "type" : "graph",
        "nodes" : [
           {
              "id" : "mol1",
              "type" : "molecule",
               "atoms" : [
                   {"id": "a1", "label" : "C", "location": [ -0.762160, 1.168557, 0.022754 ]},
                   {"id": "a2", "label" : "C", "location": [ 0.631044, 1.242862, -0.013022 ]},
                   {"id": "a3", "label" : "N", "location": [ 0.631044, 1.242862, -0.013022 ]}
               ],
               "bonds" : [
                  { "refs" : ["a1", "a2"], "order" : 1 },
                  { "refs" : ["a2", "a3"], "order" : 2 }
              ]
           },
           {
              "id": "prop1",
              "type": "map",
              "properties": [
                {
                  "key": "name",
                  "value": "benzene"
                },
                {
                  "key": "mass",
                  "value": 200
                }
              ]
           },
           {
              "id" : "mol2",
              "type" : "molecule",
               "atoms" : [
                   {"id": "a1", "label" : "C", "location": [ -0.762160, 1.168557, 0.022754 ]},
                   {"id": "a2", "label" : "C", "location": [ 0.631044, 1.242862, -0.013022 ]},
                   {"id": "a3", "label" : "N", "location": [ 0.631044, 1.242862, -0.013022 ]}
               ],
               "bonds" : [
                  { "refs" : ["a1", "a2"], "order" : 1 },
                  { "refs" : ["a2", "a3"], "order" : 2 }
              ]
           },
           {
              "id": "prop2",
              "type": "map",
              "properties": [
                {
                  "key": "name",
                  "value": "benzene"
                },
                {
                  "key": "mass",
                  "value": 200
                }
              ]
           }
        ],
        "edges" : [
            { "refs" : ["mol1", "prop1"] },
            { "refs" : ["mol2", "prop2"]}
        ]
    }
}

R Groups

// Reaction
{
  "root": {
    "nodes": [
      {
        "$ref": "mol0"
      },
      {
        "type": "plus",
        "location": [ 4.4201487709352, 10.724237873791509, 0 ],
        "prop": {}
      },
      {
        "$ref": "mol1"
      },
      {
        "$ref": "mol2"
      },
      {
        "type": "plus",
        "location": [ 9.925, 9.675, 0 ],
        "prop": {}
      },
      {
        "type": "arrow",
        "location": [ 12.103548353650336, 9.895950639370875, 0 ],
        "prop": {}
      },
      {
        "$ref": "mol3"
      },
      {
        "type": "plus",
        "location": [ 18.13344958231073, 8.317663404950244, 0 ],
        "prop": {}
      },
      {
        "$ref": "mol4"
      }
    ]
  },
  "mol0": {
    "type": "molecule",
    "atoms": [
      {
        "label": "C",
        "alias": "Hello",
        "location": [ 1.9424188114308452, 11.698729991857089, 0 ],
        "explicitValence": 4,
        "radical": 2
      },
      {
        "label": "Fe",
        "location": [ 2.6495130922765844, 10.991635711011353, 0 ],
        "ringBondCount": -1,
        "substitutionCount": 5,
        "unsaturatedAtom": true,
        "hCount": 3,
        "invRet": 2,
        "exactChangeFlag": true
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      }
    ]
  },
  "mol1": {
    "type": "molecule",
    "atoms": [
      {
        "label": "P",
        "location": [ 5.940784449593817, 10.556840036571668, 0 ],
        "isotope": 1
      },
      {
        "type": "rg-label",
        "location": [ 6.647878730439557, 9.849745755725928, 0 ],
        "attachmentPoints": 1,
        "$refs": [ "rg-3" ]
      }
    ],
    "bonds": [
      {
        "type": 3,
        "atoms": [ 0, 1 ],
        "topology": 1
      }
    ]
  },
  "mol2": {
    "type": "molecule",
    "atoms": [
      {
        "label": "O",
        "location": [ 7.841987298107781, 10.125, 0 ]
      },
      {
        "label": "O",
        "location": [ 8.708012701892219, 9.625, 0 ]
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      }
    ]
  },
  "mol3": {
    "type": "molecule",
    "atoms": [
      {
        "label": "C",
        "location": [ 15.859217976861114, 9.13405680175757, 0 ]
      },
      {
        "label": "C",
        "location": [ 16.566412256898033, 8.426962520911832, 0 ]
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      }
    ],
    "sgroups": [
      {
        "type": "SUP",
        "atoms": [ 0, 1 ],
        "name": "NameAtom"
      }
    ]
  },
  "mol4": {
    "type": "molecule",
    "atoms": [
      {
        "label": "N",
        "location": [ 19.70048690772342, 8.208364288988655, 0 ]
      },
      {
        "type": "atom-list",
        "location": [ 20.407581188569157, 7.501270008142915, 0 ],
        "elements": [ "Sg", "Tl", "Er", "Ru", "Cm" ]
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      }
    ]
  }
}
  
// RGroups
{
  "root": {
  "nodes": [
      {
        "$ref": "rg4"
      },
      {
        "$ref": "mol0"
      },
      {
        "$ref": "rg5"
      },
      {
        "$ref": "mol1"
      }
    ]
  },
  "rg4": {
    "type": "rgroup",
    "rlogic": {
      "number": 4,
      "range": ">3",
      "resth": true,
      "ifthen": 5
    },
    "atoms": [
      {
        "label": "O",
        "location": [ 16.674999999999997, 9.775, 0 ]
      },
      {
        "label": "O",
        "location": [ 17.540999999999993, 10.275, 0 ]
      },
      {
        "label": "O",
        "location": [ 18.407099999999996, 9.775, 0 ]
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      },
      {
        "type": 1,
        "atoms": [ 1, 2 ]
      }
    ]
  },
  "rg5": {
    "type": "rgroup",
    "rlogic": {
      "number": 5
    },
    "atoms": [
      {
        "label": "C",
        "location": [ 21.44198729810778, 10.300000000000002, 0 ]
      },
      {
        "label": "C",
        "location": [ 22.30801270189222, 9.800000000000002, 0 ]
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      }
    ]
  },
  "mol0": {
    "type": "molecule",
    "atoms": [
      {
        "label": "Na",
        "location": [ 15.884, 7.025, 0 ],
        "ringBondCount": -2,
        "substitutionCount": 2,
        "unsaturatedAtom": true,
        "hCount": 3
      },
      {
        "label": "Fe",
        "alias": "Hello",
        "location": [ 17.216, 7.575, 0 ],
        "explicitValence": 7
      },
      {
        "type": "atom-list",
        "location": [ 5.125, 2.55, 0 ],
        "elements": [ "Hs", "Mt", "Ds", "Rg" ]
      },
      {
        "type": "rg-label",
        "location": [ 18.475, 6.35, 0 ],
        "attachmentPoints": 1,
        "$refs": [ "rg-4", "rg-5", "rg-32" ]
      }
    ],
    "bonds": [
      {
        "type": 2,
        "atoms": [ 2, 0 ]
      },
      {
        "type": 6,
        "atoms": [ 0, 1 ],
        "topology": 2
      },
      {
        "type": 1,
        "atoms": [ 1, 3 ],
        "topology": 1,
        "center": -1
      }
    ]
  },
  "mol1": {
    "type": "molecule",
    "atoms": [
      {
        "label": "C",
        "location": [ 21.1, 6.5, 0 ]
      },
      {
        "label": "C",
        "location": [ 21.96602540378444, 7, 0 ]
      }
    ],
    "bonds": [
      {
        "type": 1,
        "atoms": [ 0, 1 ]
      }
    ],
    "sgroups": [
      {
        "type": "DAT",
        "atoms": [ 0, 1 ],
        "context": "Bond",
        "fieldName": "MDLBG_STEREO_KEY",
        "fieldData": "endo"
      },
      {
        "type": "DAT",
        "atoms": [ 0, 1 ],
        "context": "Bond",
        "fieldName": "MDLBG_STEREO_KEY",
        "fieldData": "alpha"
      }
    ]
  }
}