Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openchemlib-utils

Package Overview
Dependencies
Maintainers
4
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openchemlib-utils - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

src/hose/getHoseCodesForAtoms.js

7

CHANGELOG.md
# Changelog
## [1.8.0](https://www.github.com/cheminfo/openchemlib-utils/compare/v1.7.0...v1.8.0) (2021-12-14)
### Features
* add getHoseCodesForAtoms ([b0f2b6b](https://www.github.com/cheminfo/openchemlib-utils/commit/b0f2b6bf2dab7e6a184225eb27612aa89f659ddb))
## [1.7.0](https://www.github.com/cheminfo/openchemlib-utils/compare/v1.6.0...v1.7.0) (2021-12-14)

@@ -4,0 +11,0 @@

58

lib/index.js

@@ -280,7 +280,14 @@ 'use strict';

* @param {OCL.Molecule} originalMolecule
* @param {number} rootAtom
* @param {array<number>} rootAtoms
* @param {object} [options={}]
* @param {boolean} [options.isTagged] Specify is the atom is already tagged
* @param {boolean} [options.isTagged] Specify is the atoms are already tagged
* @param {number} [options.minSphereSize=0] Smallest hose code sphere
* @param {number} [options.maxSphereSize=4] Largest hose code sphere
* @param {number} [options.kind=FULL_HOSE_CODE] Kind of hose code, default usual sphere
*/
function getHoseCodesForAtom(originalMolecule, rootAtom, options = {}) {
function getHoseCodesForAtoms(
originalMolecule,
rootAtoms = [],
options = {},
) {
const OCL = originalMolecule.getOCL();

@@ -297,11 +304,15 @@ const {

if (!isTagged) {
let tag = tagAtom(molecule, rootAtom);
molecule.addImplicitHydrogens();
molecule.addMissingChirality();
molecule.ensureHelperArrays(OCL.Molecule.cHelperNeighbours);
// because ensuring helper reorder atoms we need to look again for it
for (let i = 0; i < molecule.getAllAtoms(); i++) {
if (tag === molecule.getAtomCustomLabel(i)) {
rootAtom = i;
break;
const tags = [];
for (let i = 0; i < rootAtoms.length; i++) {
let rootAtom = rootAtoms[i];
tags.push(tagAtom(molecule, rootAtom));
molecule.addImplicitHydrogens();
molecule.addMissingChirality();
molecule.ensureHelperArrays(OCL.Molecule.cHelperNeighbours);
// because ensuring helper reorder atoms we need to look again for it
}
rootAtoms.length = 0;
for (let j = 0; j < molecule.getAllAtoms(); j++) {
if (tags.includes(molecule.getAtomCustomLabel(j))) {
rootAtoms.push(j);
}

@@ -320,5 +331,7 @@ }

if (max === 0) {
atomList[0] = rootAtom;
atomMask[rootAtom] = true;
max = 1;
for (let rootAtom of rootAtoms) {
atomList[max] = rootAtom;
atomMask[rootAtom] = true;
max++;
}
} else {

@@ -365,2 +378,16 @@ let newMax = max;

/**
* Returns the hose code for a specific atom number
* @param {OCL.Molecule} originalMolecule
* @param {number} rootAtom
* @param {object} [options={}]
* @param {boolean} [options.isTagged] Specify is the atom is already tagged
* @param {number} [options.minSphereSize=0] Smallest hose code sphere
* @param {number} [options.maxSphereSize=4] Largest hose code sphere
* @param {number} [options.kind=FULL_HOSE_CODE] Kind of hose code, default usual sphere
*/
function getHoseCodesForAtom(originalMolecule, rootAtom, options = {}) {
return getHoseCodesForAtoms(originalMolecule, [rootAtom], options);
}
/**
* Returns the hose code for a specific marked atom

@@ -1738,2 +1765,3 @@ * @param {OCL.Molecule} diastereotopicID

exports.getHoseCodesForAtom = getHoseCodesForAtom;
exports.getHoseCodesForAtoms = getHoseCodesForAtoms;
exports.getHoseCodesForPath = getHoseCodesForPath;

@@ -1740,0 +1768,0 @@ exports.getHoseCodesFromDiastereotopicID = getHoseCodesFromDiastereotopicID;

{
"name": "openchemlib-utils",
"version": "1.7.0",
"version": "1.8.0",
"description": "Various utilities that extends openchemlib-js like HOSE codes or diastereotopic IDs",

@@ -43,2 +43,3 @@ "main": "lib/index.js",

"@babel/plugin-transform-modules-commonjs": "^7.15.4",
"@types/jest": "^27.0.3",
"cheminfo-build": "^1.1.11",

@@ -45,0 +46,0 @@ "eslint": "^7.32.0",

@@ -1,8 +0,3 @@

import { isCsp3 } from '../util/isCsp3';
import { makeRacemic } from '../util/makeRacemic';
import { tagAtom } from '../util/tagAtom';
import { getHoseCodesForAtoms } from './getHoseCodesForAtoms.js';
export const FULL_HOSE_CODE = 1;
export const HOSE_CODE_CUT_C_SP3_SP3 = 2;
/**

@@ -14,78 +9,8 @@ * Returns the hose code for a specific atom number

* @param {boolean} [options.isTagged] Specify is the atom is already tagged
* @param {number} [options.minSphereSize=0] Smallest hose code sphere
* @param {number} [options.maxSphereSize=4] Largest hose code sphere
* @param {number} [options.kind=FULL_HOSE_CODE] Kind of hose code, default usual sphere
*/
export function getHoseCodesForAtom(originalMolecule, rootAtom, options = {}) {
const OCL = originalMolecule.getOCL();
const {
minSphereSize = 0,
maxSphereSize = 4,
kind = FULL_HOSE_CODE,
isTagged = false,
} = options;
const molecule = originalMolecule.getCompactCopy();
if (!isTagged) {
let tag = tagAtom(molecule, rootAtom);
molecule.addImplicitHydrogens();
molecule.addMissingChirality();
molecule.ensureHelperArrays(OCL.Molecule.cHelperNeighbours);
// because ensuring helper reorder atoms we need to look again for it
for (let i = 0; i < molecule.getAllAtoms(); i++) {
if (tag === molecule.getAtomCustomLabel(i)) {
rootAtom = i;
break;
}
}
}
let fragment = new OCL.Molecule(0, 0);
let results = [];
let min = 0;
let max = 0;
let atomMask = new Array(molecule.getAllAtoms());
let atomList = new Array(molecule.getAllAtoms());
for (let sphere = 0; sphere <= maxSphereSize; sphere++) {
if (max === 0) {
atomList[0] = rootAtom;
atomMask[rootAtom] = true;
max = 1;
} else {
let newMax = max;
for (let i = min; i < max; i++) {
let atom = atomList[i];
for (let j = 0; j < molecule.getAllConnAtoms(atom); j++) {
let connAtom = molecule.getConnAtom(atom, j);
if (!atomMask[connAtom]) {
switch (kind) {
case FULL_HOSE_CODE:
atomMask[connAtom] = true;
atomList[newMax++] = connAtom;
break;
case HOSE_CODE_CUT_C_SP3_SP3:
if (!(isCsp3(molecule, atom) && isCsp3(molecule, connAtom))) {
atomMask[connAtom] = true;
atomList[newMax++] = connAtom;
}
break;
default:
throw new Error('getHoseCoesForAtom unknown kind');
}
}
}
}
min = max;
max = newMax;
}
molecule.copyMoleculeByAtoms(fragment, atomMask, true, null);
if (sphere >= minSphereSize) {
makeRacemic(fragment);
results.push(
fragment.getCanonizedIDCode(
OCL.Molecule.CANONIZER_ENCODE_ATOM_CUSTOM_LABELS,
),
);
}
}
return results;
return getHoseCodesForAtoms(originalMolecule, [rootAtom], options);
}

@@ -9,2 +9,3 @@ export * from './diastereotopic/addDiastereotopicMissingChirality';

export * from './hose/getHoseCodesForAtom';
export * from './hose/getHoseCodesForAtoms';
export * from './hose/getHoseCodesFromDiastereotopicID';

@@ -11,0 +12,0 @@ export * from './hose/getHoseCodesForPath';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc