partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
248 stars 61 forks source link

Are parenthesis "()" included in .kcj format? #291

Closed py-chemist closed 1 year ago

py-chemist commented 1 year ago

Hello,

I need to parse a chemical formula generated by the formula tool for a reaction drawn in Composer (.kcj format) but ran into a problem of not finding parenthesis in .kcj file. For example, when I draw Pd(Ph3)4 and save into .kcj format, I can find Pd, 4, Ph, 3 but not parenthesis "()". Am I missing something or parenthesis are not encoded in .kcj format?

Thank you very much.

partridgejiang commented 1 year ago

Hi @py-chemist, the parts inside the parenthesis are stored as a child Kekule.Formula instance in the sections array of parent formula object. From the kcj data below (some lines are omitted) such a nested structure can be found. So no explicit '(' and ')' chars are stored in kcj file.

{
    "id": "m1",
    "charge": 0,
    "formula": {
        "sections": [
            {
                "__type__": "object",
                "obj": {
                    "__type__": "Kekule.Atom",
                    "charge": 0,
                    "isotopeId": "Pd"
                },
                "count": 1
            },
            {
                "__type__": "object",
                "obj": {
                    "__type__": "Kekule.MolecularFormula",
                    "sections": [
                        {
                            "__type__": "object",
                            "obj": {
                                "__type__": "Kekule.Atom",
                                "charge": 0,
                                "isotopeId": "P"
                            },
                            "count": 1
                        },
                        {
                            "__type__": "object",
                            "obj": {
                                "__type__": "Kekule.Pseudoatom",
                                "charge": 0,
                                "atomType": "custom",
                                "symbol": "Ph"
                            },
                            "count": 3
                        }
                    ],
                    "charge": 0,
                    "radical": 0
                },
                "count": 4
            }
        ],
        "charge": 0,
        "radical": 0,
        "__type__": "Kekule.MolecularFormula"
    },
    "__type__": "Kekule.Molecule"
}

By the way, the formula should actually be Pd(PPh3)4?

py-chemist commented 1 year ago

@partridgejiang Thank you very much for your reply. Yes, I forgot to include "P".