diff --git a/packages/mf-parser/src/__tests__/MF.test.ts b/packages/mf-parser/src/__tests__/MF.test.ts index 02e15439..c33f8f11 100644 --- a/packages/mf-parser/src/__tests__/MF.test.ts +++ b/packages/mf-parser/src/__tests__/MF.test.ts @@ -416,7 +416,7 @@ describe('MF', () => { ]); expect(mf.toMF()).toBe('CC{50,50}H'); - expect(mf.toText()).toBe('HC⁽⁵⁰˙⁵⁰⁾C'); + expect(mf.toText()).toBe('HC⁽⁵⁰˒⁵⁰⁾C'); const info = mf.getInfo(); expect(info).toStrictEqual({ @@ -429,6 +429,36 @@ describe('MF', () => { }); }); + it('CC{0.5,0.5}H', () => { + const mf = new MF('HC{0.5,0.5}C'); + const parts = mf.toParts(); + expect(parts).toStrictEqual([ + [ + { kind: 'atom', value: 'C', multiplier: 1 }, + { + kind: 'isotopeRatio', + value: { atom: 'C', ratio: [0.5, 0.5] }, + multiplier: 1, + }, + { kind: 'atom', value: 'H', multiplier: 1 }, + ], + ]); + + expect(mf.toMF()).toBe('CC{0.5,0.5}H'); + expect(mf.toHtml()).toBe('HC{0.5,0.5}C'); + expect(mf.toText()).toBe('HC⁽⁰˙⁵˒⁰˙⁵⁾C'); + + const info = mf.getInfo(); + expect(info).toStrictEqual({ + monoisotopicMass: 25.00782503223, + mass: 25.520354068326025, + charge: 0, + mf: 'CC{0.5,0.5}H', + unsaturation: 2.5, + atoms: { C: 2, H: 1 }, + }); + }); + it('H(+)(H+)-1H', () => { const mf = new MF('H(+)(H+)-1H'); diff --git a/packages/mf-parser/src/__tests__/parse.test.js b/packages/mf-parser/src/__tests__/parse.test.js index 45fdd79b..81c29331 100644 --- a/packages/mf-parser/src/__tests__/parse.test.js +++ b/packages/mf-parser/src/__tests__/parse.test.js @@ -218,6 +218,13 @@ let tests = { { kind: 'anchor', value: 2 }, { kind: 'atom', value: 'H' }, ], + 'C{50,50}': [{ kind: 'isotopeRatio', value: { atom: 'C', ratio: [50, 50] } }], + 'C{0.50,0.50}': [ + { + kind: 'isotopeRatio', + value: { atom: 'C', ratio: [0.5, 0.5] }, + }, + ], }; test.each(Object.keys(tests))('parse molecular formula %s', (key) => { diff --git a/packages/mf-parser/src/parse.js b/packages/mf-parser/src/parse.js index cf6c267e..36fc5c85 100644 --- a/packages/mf-parser/src/parse.js +++ b/packages/mf-parser/src/parse.js @@ -231,13 +231,13 @@ class MFParser { this.i++; ascii = this.mf.charCodeAt(this.i); } while (ascii !== 125 && this.i <= this.mf.length); // closing curly bracket - if (substring.match(/^[\d,]+$/)) { + if (substring.match(/^[0-9.,]+$/)) { return substring.split(',').map(Number); } throw new MFError( this.mf, this.i, - 'Curly brackets should contain only number and comma', + 'Curly brackets should contain only number, dot and comma', ); } diff --git a/packages/mf-parser/src/util/subSuperscript.js b/packages/mf-parser/src/util/subSuperscript.js index ffff8975..77bb3d0f 100644 --- a/packages/mf-parser/src/util/subSuperscript.js +++ b/packages/mf-parser/src/util/subSuperscript.js @@ -16,7 +16,7 @@ export const superscript = { '{': '⁽', '}': '⁾', '.': '˙', - ',': '˙', + ',': '˒', }; export const subscript = {