cheminfo / openchemlib-js

JavaScript port of OpenChemLib
https://cheminfo.github.io/openchemlib-js/index.html
BSD 3-Clause "New" or "Revised" License
71 stars 21 forks source link

Testing smarts and query features #161

Open lpatiny opened 1 year ago

lpatiny commented 1 year ago

We currently have a problem with the 'long' for query features that prevent us to exaustively test the SmilesParser, in particular for the SMARTS parsing

it.only('smarts, check ethyl any explicit hydrogens', () => {
  const smiles = '[CH3][CH2]';
  const molecule = new Molecule(0, 0);
  const parserWithoutExplicitH = new SmilesParser({ smartsMode: 'smarts' });
  parserWithoutExplicitH.parseMolecule(smiles, { molecule });
  expect(molecule.getAllAtoms()).toBe(2);
  molecule.setAtomQueryFeature(0, Molecule.cAtomQFPiElectronShift, true);
  //molecule.setAtomQueryFeature(0, Molecule.cAtomQFSimpleFeatures, true);
  //molecule.setAtomQueryFeature(1, Molecule.cAtomQFSimpleFeatures, true);
  console.log(molecule.oclMolecule.mAtomQueryFeatures);
  console.log(molecule.getAtomQueryFeatures(0));
  const parserWithExplicitH = new SmilesParser({
    smartsMode: 'smarts',
    makeHydrogenExplicit: true,
  });
  parserWithExplicitH.parseMolecule(smiles, { molecule });
  console.log(molecule.getAtomQueryFeatures(0));
  expect(molecule.getAllAtoms()).toBe(7);
});