Skip to content

Commit

Permalink
feat: add getProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Jul 26, 2023
1 parent a7aa4af commit 073c67e
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/db/utils/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function similaritySearch(moleculesDB, query) {
queryIndex,
entry.index,
) *
1000000 -
1000000 -
Math.abs(queryMW - entry.properties.mw) / 10000;
}
searchResult.push({ similarity, entry });
Expand Down Expand Up @@ -221,7 +221,7 @@ function processResult(entries, options = {}) {
data,
idCode: entry.idCode,
properties: entry.properties,
}
};
if (keepMolecule) {
result.molecule = entry.molecule;
}
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './util/tagAtom';
export * from './util/isCsp3';
export * from './util/getMF';
export * from './util/getCharge';
export * from './util/getProperties';
export * from './util/getAtoms';
export * from './util/nbOH';
export * from './util/nbCOOH';
Expand Down
64 changes: 64 additions & 0 deletions src/util/__tests__/getProperties.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Molecule } from 'openchemlib';

import { getProperties } from '../getProperties';

test('getProperties, default options', () => {
let molecule = Molecule.fromSmiles('[NH3+]CC(=O)[O-]');
let properties = getProperties(molecule);
expect(properties).toStrictEqual({
acceptorCount: 3,
donorCount: 1,
logP: -6.870399981737137,
logS: -0.027999980375170708,
polarSurfaceArea: 67.76999855041504,
rotatableBondCount: 1,
stereoCenterCount: 0,
mf: 'C2H5NO2',
mw: 75.0667,
});
});

test('getProperties, includeToxicities', () => {
let molecule = Molecule.fromSmiles('[NH3+]CC(=O)[O-]');
let properties = getProperties(molecule, { includeToxicities: true });
expect(properties).toStrictEqual({
acceptorCount: 3,
donorCount: 1,
logP: -6.870399981737137,
logS: -0.027999980375170708,
polarSurfaceArea: 67.76999855041504,
rotatableBondCount: 1,
stereoCenterCount: 0,
mf: 'C2H5NO2',
mw: 75.0667,
mutagenic: 1,
tumorigenic: 1,
irritant: 1,
reproductiveEffective: 1,
});
});

test('getProperties, include all', () => {
let molecule = Molecule.fromSmiles('[NH3+]CC(=O)[O-]');
let properties = getProperties(molecule, {
includeToxicities: true,
includeDruglikeness: true,
});
expect(properties).toStrictEqual({
acceptorCount: 3,
donorCount: 1,
logP: -6.870399981737137,
logS: -0.027999980375170708,
polarSurfaceArea: 67.76999855041504,
rotatableBondCount: 1,
stereoCenterCount: 0,
mf: 'C2H5NO2',
mw: 75.0667,
mutagenic: 1,
tumorigenic: 1,
irritant: 1,
reproductiveEffective: 1,
drugLikeness: -3.0141666666666667,
drugScore: 0.5218060573381611,
});
});
84 changes: 84 additions & 0 deletions src/util/getProperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
let toxicityPredictor;
let druglikenessPredictor;

/**
*
* @param {import('openchemlib').Molecule} molecule
* @param {object} [options={}]
* @param {boolean} [options.includeToxicities=false]
* @param {boolean} [options.includeDruglikeness=false]
*/
export function getProperties(molecule, options = {}) {
const { includeToxicities = false, includeDruglikeness = false } = options;
const OCL = molecule.getOCL();
if (!OCL.MoleculeProperties) {
throw new Error('OCL.MoleculeProperties is not defined');
}
const props = new OCL.MoleculeProperties(molecule);
const moleculeFormula = molecule.getMolecularFormula();
const result = {
acceptorCount: props.acceptorCount,
donorCount: props.donorCount,
logP: props.logP,
logS: props.logS,
polarSurfaceArea: props.polarSurfaceArea,
rotatableBondCount: props.rotatableBondCount,
stereoCenterCount: props.stereoCenterCount,
mw: moleculeFormula.relativeWeight,
mf: moleculeFormula.formula,
};

if (includeToxicities) {
const { ToxicityPredictor } = molecule.getOCL();
if (!ToxicityPredictor) {
throw new Error('OCL.ToxicityPredictor is not defined');
}
if (!toxicityPredictor) {
toxicityPredictor = new ToxicityPredictor();
}
result.mutagenic = toxicityPredictor.assessRisk(
molecule,
ToxicityPredictor.TYPE_MUTAGENIC,
);
result.tumorigenic = toxicityPredictor.assessRisk(
molecule,
ToxicityPredictor.TYPE_TUMORIGENIC,
);
result.irritant = toxicityPredictor.assessRisk(
molecule,
ToxicityPredictor.TYPE_IRRITANT,
);
result.reproductiveEffective = toxicityPredictor.assessRisk(
molecule,
ToxicityPredictor.TYPE_REPRODUCTIVE_EFFECTIVE,
);
}

if (includeDruglikeness) {
const { DruglikenessPredictor } = molecule.getOCL();
if (!DruglikenessPredictor) {
throw new Error('OCL.DruglikenessPredictor is not defined');
}
if (!druglikenessPredictor) {
druglikenessPredictor = new DruglikenessPredictor();
}
result.drugLikeness = druglikenessPredictor.assessDruglikeness(molecule);
}

if (result.drugLikeness !== undefined && result.mutagenic !== undefined) {
result.drugScore = OCL.DrugScoreCalculator.calculate(
result.logP,
result.polarSurfaceArea,
result.mw,
result.drugLikeness,
[
result.mutagenic,
result.tumurogenic,
result.irritant,
result.reproductiveEffective,
],
);
}

return result;
}

0 comments on commit 073c67e

Please sign in to comment.