Skip to content

Commit

Permalink
feat: add getFinalRanks (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny authored Aug 13, 2023
1 parent b22396c commit 9f9974d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions __tests__/__snapshots__/library.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ exports[`prototype properties of Molecule 1`] = `
"getElectronValenceCorrection",
"getExcludedNeighbourCount",
"getExplicitHydrogens",
"getFinalRanks",
"getFisherProjectionParity",
"getFragmentAtoms",
"getFragmentNumbers",
Expand Down
43 changes: 42 additions & 1 deletion __tests__/molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Molecule', () => {
expect(mol.getChiralText()).toBe('this enantiomer');
});

it.skip('getCanonizedIDCode', () => {
it('getCanonizedIDCode', () => {
let idcode = 'didH@@RYm^Fh@BHx@';
let mol = Molecule.fromIDCode(idcode);
expect(
Expand All @@ -138,6 +138,47 @@ describe('Molecule', () => {
).toBe(idcode);
});

it('getFinalRanks', () => {
const molecule = Molecule.fromSmiles('CCC');
molecule.setAtomicNo(0, 8)
const atoms = [];
const ranks = [...molecule.getFinalRanks()];
for (let i = 0; i < molecule.getAllAtoms(); i++) {
atoms.push(molecule.getAtomLabel(i), ranks[i]);
}
expect(atoms).toStrictEqual(['O', 3, 'C', 2, 'C', 1])
const molecule2 = Molecule.fromSmiles('CCC');
molecule2.setAtomicNo(2, 8)
const atoms2 = [];
const ranks2 = [...molecule2.getFinalRanks()];
for (let i = 0; i < molecule2.getAllAtoms(); i++) {
atoms2.push(molecule2.getAtomLabel(i), ranks2[i]);
}
expect(atoms2).toStrictEqual(['C', 1, 'C', 2, 'O', 3])
})

it('getFinalRanks of xMolecule', () => {
const molecule = Molecule.fromSmiles('CCCO');
const xAtomicNumber = Molecule.getAtomicNoFromLabel(
'X',
Molecule.cPseudoAtomX,
);
molecule.addImplicitHydrogens();
for (let i = 0; i < molecule.getAllAtoms(); i++) {
// hydrogens are not taken into account during canonization, we need to change them with an atom with a valence of 1
if (molecule.getAtomicNo(i) === 1) {
molecule.setAtomicNo(i, xAtomicNumber);
}
}

const ranks = [...molecule.getFinalRanks()];
expect(ranks).toStrictEqual([
3, 1, 2, 4, 11,
10, 9, 5, 6, 7,
8, 12
])
})

it('should have a method that returns the OCL object', () => {
const molecule = Molecule.fromSmiles('C');
const OCL = molecule.getOCL();
Expand Down
9 changes: 8 additions & 1 deletion src/com/actelion/research/gwt/minimal/JSMolecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ public String getCanonizedIDCode(int flag) {
return canonizer.getIDCode();
}



public int[] getFinalRanks(int flag) {
Canonizer canonizer = new Canonizer(oclMolecule, flag);
return canonizer.getFinalRank();
}

public native JavaScriptObject getIDCodeAndCoordinates()
/*-{
return {
Expand Down Expand Up @@ -249,7 +256,7 @@ private void addImplicitHydrogens(int atomNumber) {

@JsIgnore
public static JSMolecule fromSmiles(String smiles, boolean createCoordinates,
boolean readStereoFeatures) throws Exception {
boolean readStereoFeatures) throws Exception {
SmilesParser parser = new SmilesParser();
JSMolecule mol = new JSMolecule();
parser.parse(mol.oclMolecule, smiles.getBytes(), createCoordinates, readStereoFeatures);
Expand Down
9 changes: 9 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,17 @@ export declare class Molecule {
options?: IMoleculeToSVGOptions,
): string;

/**
* Get an ID code for the molecule
* @param flag
*/
getCanonizedIDCode(flag: number): string;

/**
* Returns the canonic numbering of the atoms.
*/
getFinalRanks(flag: number): number[];

/**
* Returns an object with both the ID code and coordinates of the molecule.
*/
Expand Down

0 comments on commit 9f9974d

Please sign in to comment.