openchemlib-utils
Advanced tools
Comparing version 3.0.0 to 3.1.0
{ | ||
"name": "openchemlib-utils", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Various utilities that extends openchemlib-js like HOSE codes or diastereotopic IDs", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,2 @@ | ||
import { getXAtomicNumber } from '../util/getXAtomicNumber.js'; | ||
import { getSymmetryRanks } from '../util/getSymmetryRanks'; | ||
import { makeRacemic } from '../util/makeRacemic'; | ||
@@ -15,16 +15,4 @@ import { tagAtom } from '../util/tagAtom'; | ||
const xAtomNumber = getXAtomicNumber(molecule); | ||
const symmetryRanks = getSymmetryRanks(molecule); | ||
// most of the molecules have some symetry | ||
const internalMolecule = molecule.getCompactCopy(); | ||
for (let i = 0; i < internalMolecule.getAllAtoms(); i++) { | ||
// hydrogens are not taken into account during canonization, we need to change them with an atom with a valence of 1 | ||
if (internalMolecule.getAtomicNo(i) === 1) { | ||
internalMolecule.setAtomicNo(i, xAtomNumber); | ||
} | ||
} | ||
internalMolecule.ensureHelperArrays( | ||
Molecule.cHelperSymmetryStereoHeterotopicity, | ||
); | ||
let numberAtoms = molecule.getAllAtoms(); | ||
@@ -34,3 +22,3 @@ let ids = []; | ||
for (let iAtom = 0; iAtom < numberAtoms; iAtom++) { | ||
const rank = internalMolecule.getSymmetryRank(iAtom); | ||
const rank = symmetryRanks[iAtom]; | ||
if (rank && cache[rank]) { | ||
@@ -37,0 +25,0 @@ ids[iAtom] = cache[rank]; |
@@ -6,3 +6,3 @@ import { getDiastereotopicAtomIDsAndH } from './getDiastereotopicAtomIDsAndH.js'; | ||
* The map allows to reload properties assigned to the atom molfile | ||
* Pelase take care than numbering of atoms starts at 0 ! | ||
* Please take care than numbering of atoms starts at 0 ! | ||
* @param {import('openchemlib')} OCL - openchemlib library | ||
@@ -9,0 +9,0 @@ * @param {string} molfile |
import { ensureHeterotopicChiralBonds } from '../diastereotopic/ensureHeterotopicChiralBonds.js'; | ||
import { makeRacemic } from '../util/makeRacemic.js'; | ||
import { tagAtom } from '../util/tagAtom.js'; | ||
import { getHoseCodesForAtomsInternal } from './getHoseCodesForAtomsInternal.js'; | ||
/** | ||
@@ -15,3 +16,3 @@ * Returns the hose codes for all atoms in the molecule | ||
export function getHoseCodes(molecule, options = {}) { | ||
const { atomLabels } = options; | ||
const { atomLabels, minSphereSize, maxSphereSize } = options; | ||
const { Molecule } = molecule.getOCL(); | ||
@@ -26,5 +27,2 @@ | ||
ensureHeterotopicChiralBonds(internalMolecule); | ||
internalMolecule.ensureHelperArrays( | ||
Molecule.cHelperSymmetryStereoHeterotopicity, | ||
); | ||
@@ -40,53 +38,14 @@ const results = []; | ||
} else { | ||
results.push(getHoseCodesForAtom(internalMolecule, i, options)); | ||
} | ||
} | ||
return results; | ||
} | ||
function getHoseCodesForAtom(molecule, rootAtom, options = {}) { | ||
const { minSphereSize = 0, maxSphereSize = 4 } = options; | ||
const { Molecule } = molecule.getOCL(); | ||
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++) { | ||
let fragment = new Molecule(0, 0); | ||
if (max === 0) { | ||
atomList[max] = rootAtom; | ||
atomMask[rootAtom] = true; | ||
max++; | ||
} 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]) { | ||
atomMask[connAtom] = true; | ||
atomList[newMax++] = connAtom; | ||
} | ||
} | ||
} | ||
min = max; | ||
max = newMax; | ||
} | ||
const atomMap = []; | ||
molecule.copyMoleculeByAtoms(fragment, atomMask, false, atomMap); | ||
tagAtom(fragment, atomMap[rootAtom]); | ||
if (sphere >= minSphereSize) { | ||
makeRacemic(fragment); | ||
const tempMolecule = internalMolecule.getCompactCopy(); | ||
tagAtom(tempMolecule, i); | ||
results.push( | ||
fragment.getCanonizedIDCode( | ||
Molecule.CANONIZER_ENCODE_ATOM_CUSTOM_LABELS, | ||
), | ||
getHoseCodesForAtomsInternal(tempMolecule, { | ||
minSphereSize, | ||
maxSphereSize, | ||
}), | ||
); | ||
} | ||
} | ||
return results; | ||
} |
import { ensureHeterotopicChiralBonds } from '../diastereotopic/ensureHeterotopicChiralBonds.js'; | ||
import { isCsp3 } from '../util/isCsp3'; | ||
import { makeRacemic } from '../util/makeRacemic'; | ||
import { tagAtom } from '../util/tagAtom'; | ||
import { getHoseCodesForAtomsInternal } from './getHoseCodesForAtomsInternal.js'; | ||
export const FULL_HOSE_CODE = 1; | ||
@@ -14,3 +14,2 @@ export const HOSE_CODE_CUT_C_SP3_SP3 = 2; | ||
* @param {object} [options={}] | ||
* @param {boolean} [options.isTagged] Specify is the atoms are already tagged | ||
* @param {number} [options.minSphereSize=0] Smallest hose code sphere | ||
@@ -25,3 +24,2 @@ * @param {number} [options.maxSphereSize=4] Largest hose code sphere | ||
) { | ||
const OCL = originalMolecule.getOCL(); | ||
const { | ||
@@ -31,77 +29,21 @@ minSphereSize = 0, | ||
kind = FULL_HOSE_CODE, | ||
isTagged = false, | ||
} = options; | ||
const molecule = originalMolecule.getCompactCopy(); | ||
// those 2 lines should be done only once | ||
molecule.addImplicitHydrogens(); | ||
ensureHeterotopicChiralBonds(molecule); | ||
if (!isTagged) { | ||
const tags = []; | ||
for (let i = 0; i < rootAtoms.length; i++) { | ||
let rootAtom = rootAtoms[i]; | ||
tags.push(tagAtom(molecule, rootAtom)); | ||
molecule.addImplicitHydrogens(); | ||
ensureHeterotopicChiralBonds(molecule); | ||
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); | ||
} | ||
} | ||
const allowedCustomLabels = []; | ||
for (let i = 0; i < rootAtoms.length; i++) { | ||
let rootAtom = rootAtoms[i]; | ||
allowedCustomLabels.push(tagAtom(molecule, rootAtom)); | ||
} | ||
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) { | ||
for (let rootAtom of rootAtoms) { | ||
atomList[max] = rootAtom; | ||
atomMask[rootAtom] = true; | ||
max++; | ||
} | ||
} 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 getHoseCodesForAtomsInternal(molecule, { | ||
minSphereSize, | ||
maxSphereSize, | ||
allowedCustomLabels, | ||
kind, | ||
}); | ||
} |
import { ensureHeterotopicChiralBonds } from '../diastereotopic/ensureHeterotopicChiralBonds.js'; | ||
import { getHoseCodesForAtom } from './getHoseCodesForAtom'; | ||
import { getHoseCodesForAtomsInternal } from './getHoseCodesForAtomsInternal.js'; | ||
/** | ||
* Returns the hose code for a specific marked atom | ||
* @param {import('openchemlib').Molecule} diastereotopicID | ||
* @param {import('openchemlib').Molecule} molecule | ||
* @param {object} options | ||
@@ -13,18 +13,3 @@ */ | ||
ensureHeterotopicChiralBonds(molecule); | ||
// One of the atom has to be marked ! | ||
let atomID = -1; | ||
for (let i = 0; i < molecule.getAllAtoms(); i++) { | ||
// we need to find the marked atom | ||
const atomCustomLabel = molecule.getAtomCustomLabel(i); | ||
if (atomCustomLabel != null && atomCustomLabel.endsWith('*')) { | ||
atomID = i; | ||
break; | ||
} | ||
} | ||
if (atomID >= 0) { | ||
options.isTagged = true; | ||
return getHoseCodesForAtom(molecule, atomID, options); | ||
} | ||
return undefined; | ||
return getHoseCodesForAtomsInternal(molecule, options); | ||
} |
@@ -15,2 +15,3 @@ export * from './diastereotopic/ensureHeterotopicChiralBonds'; | ||
export * from './hose/getHoseCodesForPath'; | ||
export * from './hose/getHosesAndInfoFromMolfile'; | ||
@@ -17,0 +18,0 @@ export * from './util/combineSmiles'; |
let xAtomicNumber = 0; | ||
/** | ||
* Returns the atomic number of the X atom | ||
* @param {import('openchemlib').Molecule} molecule An instance of a molecule | ||
* @returns | ||
*/ | ||
export function getXAtomicNumber(molecule) { | ||
@@ -4,0 +9,0 @@ if (!xAtomicNumber) { |
@@ -19,2 +19,5 @@ /** | ||
} | ||
// after the change we need to recalculate the CIP | ||
molecule.ensureHelperArrays(Molecule.cHelperCIP); | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
320758
79
6364