Skip to content

Commit

Permalink
feat: add method Molecule.getAtomQueryFeaturesObject
Browse files Browse the repository at this point in the history
* wip: add getAtomQueryFeaturesObject

* create PlainJSObject class

* feat: add method Molecule.getAtomQueryFeaturesObject

---------

Co-authored-by: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
lpatiny and targos authored May 27, 2024
1 parent 39b2421 commit c1843b8
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 1 deletion.
1 change: 1 addition & 0 deletions __tests__/__snapshots__/library.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ exports[`prototype properties of Molecule 1`] = `
"getAtomParity",
"getAtomPi",
"getAtomPreferredStereoBond",
"getAtomQueryFeaturesObject",
"getAtomRadical",
"getAtomRingBondCount",
"getAtomRingCount",
Expand Down
23 changes: 23 additions & 0 deletions __tests__/molecule.queryFeatures.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const { Molecule } = require('../minimal');

test('queryFeatures more than 2 neighbours', () => {
const molecule = Molecule.fromIDCode('eF@Hp[qp');

const firstQueryFeatures = molecule.getAtomQueryFeaturesObject(0);
expect(firstQueryFeatures.not0Neighbours).toBe(true);
expect(firstQueryFeatures.not1Neighbours).toBe(true);
expect(firstQueryFeatures.not2Neighbours).toBe(true);
expect(firstQueryFeatures.not3Neighbours).toBe(false);

});

test('queryFeatures exactly 2 hydrogens', () => {
const molecule = Molecule.fromIDCode('eF@Hp_Qh');
const firstQueryFeatures = molecule.getAtomQueryFeaturesObject(0);
expect(firstQueryFeatures.not0Hydrogen).toBe(true);
expect(firstQueryFeatures.not1Hydrogen).toBe(true);
expect(firstQueryFeatures.not2Hydrogen).toBe(false);
expect(firstQueryFeatures.not3Hydrogen).toBe(true);
});
8 changes: 7 additions & 1 deletion src/com/actelion/research/gwt/minimal/JSMolecule.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.actelion.research.gwt.minimal;

import com.actelion.research.gwt.minimal.MoleculeQueryFeatures;
import java.util.HashMap;
import java.util.Set;
import java.util.Vector;
Expand Down Expand Up @@ -947,6 +948,11 @@ public int getAtomParity(int atom) {
// return oclMolecule.getAtomQueryFeatures(atom);
// }

public JavaScriptObject getAtomQueryFeaturesObject(int atom) {
return MoleculeQueryFeatures.getAtomQueryFeatures(oclMolecule, atom);
}


public int getAtomRadical(int atom) {
return oclMolecule.getAtomRadical(atom);
}
Expand Down Expand Up @@ -1741,4 +1747,4 @@ public void setUnknownParitiesToExplicitlyUnknown() {
public void setAssignParitiesToNitrogen(boolean b) {
oclMolecule.setAssignParitiesToNitrogen(b);
}
}
};
83 changes: 83 additions & 0 deletions src/com/actelion/research/gwt/minimal/MoleculeQueryFeatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.actelion.research.gwt.minimal;

import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.Molecule;
import com.google.gwt.core.client.JavaScriptObject;

class MoleculeQueryFeatures {
public static JavaScriptObject getAtomQueryFeatures(StereoMolecule oclMolecule, int atom) {
PlainJSObject moleculeQueryFeatures = PlainJSObject.create();

moleculeQueryFeatures.setPropertyBoolean("aromatic",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFAromatic) > 0);
moleculeQueryFeatures.setPropertyBoolean("notAromatic",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNotAromatic) > 0);

moleculeQueryFeatures.setPropertyBoolean("notChain",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNotChain) > 0);
moleculeQueryFeatures.setPropertyBoolean("not2RingBonds",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot2RingBonds) > 0);
moleculeQueryFeatures.setPropertyBoolean("not3RingBonds",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot3RingBonds) > 0);
moleculeQueryFeatures.setPropertyBoolean("not4RingBonds",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot4RingBonds) > 0);

moleculeQueryFeatures.setPropertyBoolean("noMoreNeighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNoMoreNeighbours) > 0);
moleculeQueryFeatures.setPropertyBoolean("moreNeighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFMoreNeighbours) > 0);
moleculeQueryFeatures.setPropertyBoolean("matchStereo",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFMatchStereo) > 0);

moleculeQueryFeatures.setPropertyBoolean("not0PiElectrons",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot0PiElectrons) > 0);
moleculeQueryFeatures.setPropertyBoolean("not1PiElectrons",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot1PiElectron) > 0);
moleculeQueryFeatures.setPropertyBoolean("not2PiElectrons",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot2PiElectrons) > 0);

moleculeQueryFeatures.setPropertyBoolean("not0Hydrogen",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot0Hydrogen) > 0);
moleculeQueryFeatures.setPropertyBoolean("not1Hydrogen",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot1Hydrogen) > 0);
moleculeQueryFeatures.setPropertyBoolean("not2Hydrogen",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot2Hydrogen) > 0);
moleculeQueryFeatures.setPropertyBoolean("not3Hydrogen",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot3Hydrogen) > 0);

moleculeQueryFeatures.setPropertyBoolean("not0Neighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot0Neighbours) > 0);
moleculeQueryFeatures.setPropertyBoolean("not1Neighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot0Neighbours) > 0);
moleculeQueryFeatures.setPropertyBoolean("not2Neighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot2Neighbours) > 0);
moleculeQueryFeatures.setPropertyBoolean("not3Neighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot3Neighbours) > 0);
moleculeQueryFeatures.setPropertyBoolean("not4Neighbours",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNot4Neighbours) > 0);

moleculeQueryFeatures.setPropertyBoolean("notChargeNeg",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNotChargeNeg) > 0);
moleculeQueryFeatures.setPropertyBoolean("notCharge0",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNotCharge0) > 0);
moleculeQueryFeatures.setPropertyBoolean("noChargePos",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFNotChargePos) > 0);

moleculeQueryFeatures.setPropertyBoolean("ringSize0",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSize0) > 0);
moleculeQueryFeatures.setPropertyBoolean("ringSize3",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSize3) > 0);
moleculeQueryFeatures.setPropertyBoolean("ringSize4",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSize4) > 0);
moleculeQueryFeatures.setPropertyBoolean("ringSize5",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSize5) > 0);
moleculeQueryFeatures.setPropertyBoolean("ringSize6",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSize6) > 0);
moleculeQueryFeatures.setPropertyBoolean("ringSize7",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSize7) > 0);
moleculeQueryFeatures.setPropertyBoolean("ringSizeLarge",
(oclMolecule.getAtomQueryFeatures(atom) & Molecule.cAtomQFRingSizeLarge) > 0);

return moleculeQueryFeatures;
}
}
23 changes: 23 additions & 0 deletions src/com/actelion/research/gwt/minimal/PlainJSObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.actelion.research.gwt.minimal;

import com.google.gwt.core.client.JavaScriptObject;

public class PlainJSObject extends JavaScriptObject {
protected PlainJSObject() {}

public static PlainJSObject create() {
return (PlainJSObject) JavaScriptObject.createObject().cast();
}

public native final void setPropertyString(String key, String value)/*-{
this[key] = value;
}-*/;

public native final void setPropertyInt(String key, int value)/*-{
this[key] = value;
}-*/;

public native final void setPropertyBoolean(String key, boolean value)/*-{
this[key] = value;
}-*/;
}
40 changes: 40 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ export interface IMoleculeFromSmilesOptions {
noStereo?: boolean;
}

export interface AtomQueryFeatures {
aromatic: boolean;
notAromatic: boolean;
notChain: boolean;
not2RingBonds: boolean;
not3RingBonds: boolean;
not4RingBonds: boolean;
noMoreNeighbours: boolean;
moreNeighbours: boolean;
matchStereo: boolean;
not0PiElectrons: boolean;
not1PiElectrons: boolean;
not2PiElectrons: boolean;
not0Hydrogen: boolean;
not1Hydrogen: boolean;
not2Hydrogen: boolean;
not3Hydrogen: boolean;
not0Neighbours: boolean;
not1Neighbours: boolean;
not2Neighbours: boolean;
not3Neighbours: boolean;
not4Neighbours: boolean;
notChargeNeg: boolean;
notCharge0: boolean;
noChargePos: boolean;
ringSize0: boolean;
ringSize3: boolean;
ringSize4: boolean;
ringSize5: boolean;
ringSize6: boolean;
ringSize7: boolean;
ringSizeLarge: boolean;
}

export interface IMoleculeToSVGOptions extends IDepictorOptions {
/**
* Factor used to compute the size of text nodes.
Expand Down Expand Up @@ -905,6 +939,12 @@ export declare class Molecule {
*/
getAtomLabel(atom: number): string;

/**
* Get the atomic query features as an object
* @param atom
*/
getAtomQueryFeaturesObject(atom: number): AtomQueryFeatures;

/**
* The list of atoms that are allowed at this position during sub-structure
* search. (or refused atoms, if atom query feature cAtomQFAny is set).
Expand Down

0 comments on commit c1843b8

Please sign in to comment.