Skip to content

Commit

Permalink
fix: split groupedDiastereotopicAtomIDs (#42)
Browse files Browse the repository at this point in the history
new function groupDiastereotopicAtomIDs exposed 

* fix: split groupedDiasterotopicAtomIDs

* chore: update dependencies
  • Loading branch information
jobo322 authored Nov 28, 2022
1 parent 4a550db commit 8e1ee5a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Binary file added src/diastereotopic/.DS_Store
Binary file not shown.
23 changes: 3 additions & 20 deletions src/diastereotopic/getGroupedDiastereotopicAtomIDs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getDiastereotopicAtomIDs } from './getDiastereotopicAtomIDs';
import { groupDiastereotopicAtomIDs } from './groupDiastereotopicAtomIDs';
/**
* This function groups the diasterotopic atomIds of the molecule based on equivalence of atoms. The output object contains
* a set of chemically equivalent atoms(element.atoms) and the groups of magnetically equivalent atoms (element.magneticGroups)
Expand All @@ -9,24 +10,6 @@ import { getDiastereotopicAtomIDs } from './getDiastereotopicAtomIDs';
*/

export function getGroupedDiastereotopicAtomIDs(molecule, options = {}) {
const { atomLabel } = options;
let diaIDs = getDiastereotopicAtomIDs(molecule, options);
let diaIDsObject = {};
for (let i = 0; i < diaIDs.length; i++) {
if (!atomLabel || molecule.getAtomLabel(i) === atomLabel) {
let diaID = diaIDs[i];
if (!diaIDsObject[diaID]) {
diaIDsObject[diaID] = {
counter: 0,
atoms: [],
oclID: diaID,
atomLabel: molecule.getAtomLabel(i),
};
}
diaIDsObject[diaID].counter++;
diaIDsObject[diaID].atoms.push(i);
}
}

return Object.values(diaIDsObject);
let diaIDs = getDiastereotopicAtomIDs(molecule);
return groupDiastereotopicAtomIDs(diaIDs, molecule, options);
}
21 changes: 21 additions & 0 deletions src/diastereotopic/groupDiastereotopicAtomIDs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function groupDiastereotopicAtomIDs(diaIDs, molecule, options) {
const { atomLabel } = options;
const diaIDsObject = {};
for (let i = 0; i < diaIDs.length; i++) {
if (!atomLabel || molecule.getAtomLabel(i) === atomLabel) {
let diaID = diaIDs[i];
if (!diaIDsObject[diaID]) {
diaIDsObject[diaID] = {
counter: 0,
atoms: [],
oclID: diaID,
atomLabel: molecule.getAtomLabel(i),
};
}
diaIDsObject[diaID].counter++;
diaIDsObject[diaID].atoms.push(i);
}
}

return Object.keys(diaIDsObject).map((key) => diaIDsObject[key]);
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './diastereotopic/getDiastereotopicAtomIDsAndH';
export * from './diastereotopic/toDiastereotopicSVG';
export * from './diastereotopic/getGroupedDiastereotopicAtomIDs';
export * from './diastereotopic/getDiastereotopicAtomIDsFromMolfile';
export * from './diastereotopic/groupDiastereotopicAtomIDs';

export * from './hose/getHoseCodesAndDiastereotopicIDs';
export * from './hose/getHoseCodesForAtom';
Expand Down

0 comments on commit 8e1ee5a

Please # to comment.