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

openchemlib-utils

Package Overview
Dependencies
Maintainers
6
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 0.2.0 to 0.2.1

87

lib/index.js

@@ -9,2 +9,3 @@ 'use strict';

var mlMatrix = require('ml-matrix');
var atomSorter = _interopDefault(require('atom-sorter'));

@@ -552,2 +553,87 @@ let OCL;

/**
* Calculate the molecular formula in 'chemcalc' notation taking into account fragments, isotopes and charges
* {OCL.Molecule} [molecule] an instance of OCL.Molecule
* @returns {String}
*/
function getMF(molecule) {
let entries = molecule.getFragments();
let result = {};
let parts = [];
let allAtoms = [];
entries.forEach(function(entry) {
let mf = getFragmentMF(entry, allAtoms);
parts.push(mf);
});
let counts = {};
for (let part of parts) {
if (!counts[part]) counts[part] = 0;
counts[part]++;
}
parts = [];
for (let key of Object.keys(counts).sort()) {
if (counts[key] > 1) {
parts.push(counts[key] + key);
} else {
parts.push(key);
}
}
result.parts = parts;
result.mf = toMFString(allAtoms);
return result;
}
function getFragmentMF(molecule, allAtoms) {
let atoms = [];
for (let i = 0; i < molecule.getAllAtoms(); i++) {
let atom = {};
atom.charge = molecule.getAtomCharge(i);
atom.label = molecule.getAtomLabel(i);
atom.mass = molecule.getAtomMass(i);
atom.implicitHydrogens = molecule.getImplicitHydrogens(i);
atoms.push(atom);
allAtoms.push(atom);
}
return toMFString(atoms);
}
function toMFString(atoms) {
let charge = 0;
let mfs = {};
for (let atom of atoms) {
let label = atom.label;
charge += atom.charge;
if (atom.mass) {
label = `[${atom.mass}${label}]`;
}
let mfAtom = mfs[label];
if (!mfAtom) {
mfs[label] = 0;
}
mfs[label] += 1;
if (atom.implicitHydrogens) {
if (!mfs.H) mfs.H = 0;
mfs.H += atom.implicitHydrogens;
}
}
let mf = '';
let keys = Object.keys(mfs).sort(atomSorter);
for (let key of keys) {
mf += key;
if (mfs[key] > 1) mf += mfs[key];
}
if (charge > 0) {
mf += `(+${charge > 1 ? charge : ''})`;
} else if (charge < 0) {
mf += `(${charge < -1 ? charge : '-'})`;
}
return mf;
}
let fragment;

@@ -780,2 +866,3 @@

exports.getHoseCodesFromDiastereotopicID = getHoseCodesFromDiastereotopicID;
exports.getMF = getMF;
exports.getOCL = getOCL;

@@ -782,0 +869,0 @@ exports.getPathsInfo = getPathsInfo;

2

package.json
{
"name": "openchemlib-utils",
"version": "0.2.0",
"version": "0.2.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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

export * from './util/isCsp3';
export * from './util/getMF';

@@ -17,0 +18,0 @@ export * from './path/getPathsInfo';

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