@@ -14,22 +14,23 @@ export function fromJSON(
1414
1515 const molecules : StateMoleculeExtended [ ] = [ ] ;
1616 for ( const mol of mols ) {
17- const molecule = Molecule . fromMolfile ( mol . molfile ) ;
18-
19- const atomCount = molecule . getAllAtoms ( ) ;
20-
21- if ( atomCount === 0 ) {
22- continue ;
23- }
24-
17+ const {
18+ molfile,
19+ label = `P${ getLabelNumber ( reservedNumbers ) } ` ,
20+ id,
21+ ...others
22+ } = mol ;
2523 const moleculeOverride = {
26- ...mol ,
27- molfile : molecule . toMolfileV3 ( ) ,
28- label : mol . label || `P ${ getLabelNumber ( reservedNumbers ) } ` ,
29- id : mol . id ,
24+ ...others ,
25+ text : molfile ,
26+ label,
27+ id,
3028 } ;
31-
32- molecules . push ( initMolecule ( moleculeOverride ) ) ;
29+ try {
30+ molecules . push ( initMolecule ( moleculeOverride ) ) ;
31+ } catch {
32+ continue ;
33+ }
3334 }
3435
3536 return molecules ;
@@ -49,10 +50,9 @@ export function addMolfile(
4950
5051 // try to parse molfile
5152 // this will throw if the molecule can not be parsed !
52- const molecule = Molecule . fromMolfile ( molfile ) ;
5353 molecules . push (
5454 initMolecule ( {
55- molfile : molecule . toMolfileV3 ( ) ,
55+ text : molfile ,
5656 label : label ?? `P${ getLabelNumber ( reservedNumbers ) } ` ,
5757 id,
5858 } ) ,
@@ -66,9 +66,8 @@ export function setMolfile(
6666 const { molfile, id, label } = currentMolecule ;
6767 // try to parse molfile
6868 // this will throw if the molecule can not be parsed !
69- const molecule = Molecule . fromMolfile ( molfile ) ;
7069 const _mol = initMolecule ( {
71- molfile : molecule . toMolfileV3 ( ) ,
70+ text : molfile ,
7271 id,
7372 label,
7473 } ) ;
@@ -148,26 +147,12 @@ function parseSDF(text: string) {
148147 }
149148}
150149
151- function parseMolText ( text : string ) {
152- let molecule : Molecule | null ;
153- try {
154- molecule = Molecule . fromText ( text ) ;
155- } catch ( error ) {
156- throw new Error ( parseErrorMessage , { cause : error } ) ;
157- }
158-
159- if ( ! molecule ) {
160- throw new Error ( parseErrorMessage ) ;
161- }
162-
163- return [ initMolecule ( { molecule } ) ] ;
164- }
165150export function getMolecules ( text ?: string ) {
166151 if ( ! text ?. trim ( ) ) {
167152 throw new Error ( parseErrorMessage ) ;
168153 }
169154
170155 const isSDF = / v [ 2 3 ] 0 0 0 / i. test ( text ) ;
171156
172- return isSDF ? parseSDF ( text ) : parseMolText ( text ) ;
157+ return isSDF ? parseSDF ( text ) : [ initMolecule ( { text } ) ] ;
173158}
0 commit comments