1+ import type { Molecule } from 'openchemlib' ;
2+
13import { getXAtomicNumber } from '../util/getXAtomicNumber.js' ;
24import { isCsp3 } from '../util/isCsp3.js' ;
35import { makeRacemic } from '../util/makeRacemic.js' ;
4- import { tagAtom } from '../util/tagAtom.ts' ;
6+ import { tagAtom } from '../util/tagAtom.js' ;
7+
8+ import type { HoseCodesForAtomsOptions } from './HoseCodesForAtomsOptions.js' ;
59
610export const FULL_HOSE_CODE = 1 ;
711export const HOSE_CODE_CUT_C_SP3_SP3 = 2 ;
812
913/**
1014 * Returns an array of hose code fragments for the specified molecule.
11- * @param {import('openchemlib').Molecule } molecule - The OCL molecule to process.
12- * @param {object } options - Options for generating hose codes.
13- * @param {string[] } [options.allowedCustomLabels] - Array of the custom labels that are considered as root atoms. By default all atoms having a customLabel
14- * @param {number } [options.minSphereSize=0] - Smallest hose code sphere
15- * @param {number } [options.maxSphereSize=4] - Largest hose code sphere
16- * @param {number } [options.kind=FULL_HOSE_CODE] - Kind of hose code, default usual sphere
17- * @param {number[] } [options.rootAtoms=[]] - Array of atom from which we should start to create the HOSE. By default we will used the taggedAtoms
18- * @param {number[] } [options.tagAtoms=[]] - Array of atom indices to tag as root atoms
19- * @param {Function } [options.tagAtomFct=tagAtom] - Function to tag an atom as root atom. By default it is defined internal
20- * @returns {Array } - An array of hose code fragments.
15+ * @param molecule - The OCL molecule to process.
16+ * @param options - Options for generating hose codes.
17+ * @returns An array of hose code fragments.
2118 */
22- export function getHoseCodesForAtomsAsFragments ( molecule , options = { } ) {
19+ export function getHoseCodesForAtomsAsFragments (
20+ molecule : Molecule ,
21+ options : HoseCodesForAtomsOptions = { } ,
22+ ) : Molecule [ ] {
2323 const OCL = molecule . getOCL ( ) ;
2424 const {
2525 allowedCustomLabels,
@@ -51,14 +51,14 @@ export function getHoseCodesForAtomsAsFragments(molecule, options = {}) {
5151 }
5252 }
5353
54- const fragments = [ ] ;
54+ const fragments : Molecule [ ] = [ ] ;
5555
5656 // keep track of the atoms when creating the fragment
57- const mappings = [ ] ;
57+ const mappings : number [ ] = [ ] ;
5858 let min = 0 ;
5959 let max = 0 ;
60- const atomMask = new Uint8Array ( molecule . getAllAtoms ( ) ) ;
61- const atomList = new Uint8Array ( molecule . getAllAtoms ( ) ) ;
60+ const atomMask = new Array < boolean > ( molecule . getAllAtoms ( ) ) . fill ( false ) ;
61+ const atomList = new Array < number > ( molecule . getAllAtoms ( ) ) ;
6262
6363 for ( let sphere = 0 ; sphere <= maxSphereSize ; sphere ++ ) {
6464 if ( max === 0 ) {
@@ -70,7 +70,7 @@ export function getHoseCodesForAtomsAsFragments(molecule, options = {}) {
7070 } else {
7171 let newMax = max ;
7272 for ( let i = min ; i < max ; i ++ ) {
73- const atom = atomList [ i ] ;
73+ const atom = atomList [ i ] as number ;
7474 for ( let j = 0 ; j < molecule . getAllConnAtoms ( atom ) ; j ++ ) {
7575 const connAtom = molecule . getConnAtom ( atom , j ) ;
7676 if ( ! atomMask [ connAtom ] ) {
@@ -117,10 +117,13 @@ export function getHoseCodesForAtomsAsFragments(molecule, options = {}) {
117117 * If the atom is not an halogen, X or an hydrogen
118118 * we add query features to the atom
119119 * This includes aromaticity, ring size, number of hydrogens
120- * @param { import('openchemlib').Molecule } fragment
121- * @param { import('openchemlib').Molecule } molecule
120+ * @param fragment
121+ * @param molecule
122122 */
123- function addQueryFeaturesAndRemoveMapNo ( fragment , molecule ) {
123+ function addQueryFeaturesAndRemoveMapNo (
124+ fragment : Molecule ,
125+ molecule : Molecule ,
126+ ) {
124127 const Molecule = molecule . getOCL ( ) . Molecule ;
125128 for ( let i = 0 ; i < fragment . getAllAtoms ( ) ; i ++ ) {
126129 const mapping = fragment . getAtomMapNo ( i ) - 1 ;
@@ -193,7 +196,12 @@ function addQueryFeaturesAndRemoveMapNo(fragment, molecule) {
193196
194197// tagging atoms may change the order of the atoms because hydrogens must be at the end of the file
195198// in order to remember the rootAtoms we will tag before
196- function internalTagAtoms ( molecule , tagAtoms , rootAtoms , tagAtomFct ) {
199+ function internalTagAtoms (
200+ molecule : Molecule ,
201+ tagAtoms : number [ ] ,
202+ rootAtoms : number [ ] ,
203+ tagAtomFct : ( molecule : Molecule , atomIndex : number ) => void ,
204+ ) {
197205 const OCL = molecule . getOCL ( ) ;
198206
199207 if ( tagAtoms ) {
@@ -216,7 +224,7 @@ function internalTagAtoms(molecule, tagAtoms, rootAtoms, tagAtomFct) {
216224 mapping [ molecule . getAtomMapNo ( i ) - 1 ] = i ;
217225 }
218226 for ( let i = 0 ; i < rootAtoms . length ; i ++ ) {
219- rootAtoms [ i ] = mapping [ rootAtoms [ i ] ] ;
227+ rootAtoms [ i ] = mapping [ rootAtoms [ i ] as number ] as number ;
220228 }
221229 }
222230}
0 commit comments