@openchemistry/cjson-utils
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.1.0"></a> | ||
# [0.1.0](https://github.com/OpenChemistry/oc-web-components/compare/@openchemistry/cjson-utils@0.0.5...@openchemistry/cjson-utils@0.1.0) (2018-06-18) | ||
### Features | ||
* Add animation of a molecule's normal modes ([f4517f7](https://github.com/OpenChemistry/oc-web-components/commit/f4517f7)) | ||
<a name="0.0.5"></a> | ||
@@ -8,0 +19,0 @@ ## [0.0.5](https://github.com/OpenChemistry/oc-web-components/compare/@openchemistry/cjson-utils@0.0.4...@openchemistry/cjson-utils@0.0.5) (2018-06-17) |
import { numberOfAtoms } from './validation'; | ||
import { isNil } from "lodash-es"; | ||
export { cjsonToMoljs }; | ||
@@ -19,3 +20,3 @@ var elementSymbols = [ | ||
var atoms = atomsToMoljs(cjson.atoms); | ||
if (cjson.bonds) { | ||
if (!isNil(cjson.bonds)) { | ||
atoms = bondsToMoljs(cjson.atoms, cjson.bonds, atoms); | ||
@@ -51,3 +52,3 @@ } | ||
var jAtom = bondsIn.connections.index[i * 2 + 1]; | ||
if (atoms[iAtom].bonds === undefined) { | ||
if (isNil(atoms[iAtom].bonds)) { | ||
atoms[iAtom].bonds = []; | ||
@@ -57,3 +58,3 @@ } | ||
if (bondsIn.order) { | ||
if (atoms[iAtom].bondOrder === undefined) { | ||
if (isNil(atoms[iAtom].bondOrder)) { | ||
atoms[iAtom].bondOrder = []; | ||
@@ -60,0 +61,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { isNil } from "lodash-es"; | ||
export { validateChemJson, isChemJson, numberOfAtoms }; | ||
@@ -9,3 +10,3 @@ function isChemJson(obj) { | ||
} | ||
if (obj.bonds) { | ||
if (!isNil(obj.bonds)) { | ||
// If bonds are invalid, throw them out but still keep the atoms | ||
@@ -16,3 +17,3 @@ if (!validateBonds(obj.atoms, obj.bonds)) { | ||
} | ||
if (obj.cube) { | ||
if (!isNil(obj.cube)) { | ||
// If cube data is invalid, throw it out but still keep the rest | ||
@@ -23,2 +24,8 @@ if (!validateCube(obj.cube)) { | ||
} | ||
if (!isNil(obj.vibrations)) { | ||
// If vibration data is invalid, throw it out but still keep the rest | ||
if (!validateVibrations(obj.atoms, obj.vibrations)) { | ||
obj.vibrations = undefined; | ||
} | ||
} | ||
return true; | ||
@@ -38,3 +45,3 @@ } | ||
var nAtoms = numberOfAtoms(atoms); | ||
if (bonds.order) { | ||
if (!isNil(bonds.order)) { | ||
if (bonds.order.length * 2 !== bonds.connections.index.length) { | ||
@@ -63,4 +70,29 @@ return false; | ||
} | ||
function validateVibrations(atoms, vibrations) { | ||
if (isNil(vibrations.modes)) { | ||
return false; | ||
} | ||
var nModes = vibrations.modes.length; | ||
if (vibrations.frequencies && vibrations.frequencies.length !== nModes) { | ||
return false; | ||
} | ||
if (!isNil(vibrations.intensities) && vibrations.intensities.length !== nModes) { | ||
return false; | ||
} | ||
if (!isNil(vibrations.eigenVectors)) { | ||
if (vibrations.eigenVectors.length !== nModes) { | ||
return false; | ||
} | ||
var nAtoms = numberOfAtoms(atoms); | ||
for (var _i = 0, _a = vibrations.eigenVectors; _i < _a.length; _i++) { | ||
var eigenVector = _a[_i]; | ||
if (eigenVector.length !== nAtoms * 3) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
function numberOfAtoms(atoms) { | ||
if (atoms.elements.number && atoms.elements.symbol) { | ||
if (!isNil(atoms.elements.number) && !isNil(atoms.elements.symbol)) { | ||
if (atoms.elements.number.length !== atoms.elements.symbol.length) { | ||
@@ -71,6 +103,6 @@ return -1; | ||
} | ||
else if (atoms.elements.number) { | ||
else if (!isNil(atoms.elements.number)) { | ||
return atoms.elements.number.length; | ||
} | ||
else if (atoms.elements.symbol) { | ||
else if (!isNil(atoms.elements.symbol)) { | ||
return atoms.elements.symbol.length; | ||
@@ -77,0 +109,0 @@ } |
{ | ||
"name": "@openchemistry/cjson-utils", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Utilities to validate and convert cjson chemical data", | ||
@@ -22,3 +22,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@openchemistry/types": "^0.0.6" | ||
"@openchemistry/types": "^0.1.0", | ||
"@types/lodash-es": "^4.17.0", | ||
"lodash-es": "^4.17.10" | ||
}, | ||
@@ -25,0 +27,0 @@ "devDependencies": { |
import { IChemJson, IAtoms, IBonds, IAtomSpec } from '@openchemistry/types'; | ||
import { numberOfAtoms } from './validation'; | ||
import { isNil } from "lodash-es"; | ||
@@ -23,3 +24,3 @@ export { cjsonToMoljs }; | ||
let atoms = atomsToMoljs(cjson.atoms); | ||
if (cjson.bonds) { | ||
if (!isNil(cjson.bonds)) { | ||
atoms = bondsToMoljs(cjson.atoms, cjson.bonds, atoms); | ||
@@ -59,3 +60,3 @@ } | ||
let jAtom: number = bondsIn.connections.index[i * 2 + 1]; | ||
if (atoms[iAtom].bonds === undefined) { | ||
if (isNil(atoms[iAtom].bonds)) { | ||
atoms[iAtom].bonds = []; | ||
@@ -65,3 +66,3 @@ } | ||
if (bondsIn.order) { | ||
if (atoms[iAtom].bondOrder === undefined) { | ||
if (isNil(atoms[iAtom].bondOrder)) { | ||
atoms[iAtom].bondOrder = []; | ||
@@ -68,0 +69,0 @@ } |
@@ -1,2 +0,3 @@ | ||
import { IChemJson, IAtoms, IBonds, ICube } from '@openchemistry/types'; | ||
import { IChemJson, IAtoms, IBonds, ICube, IVibrations } from '@openchemistry/types'; | ||
import { isNil } from "lodash-es"; | ||
@@ -13,3 +14,3 @@ export { validateChemJson, isChemJson, numberOfAtoms }; | ||
} | ||
if (obj.bonds) { | ||
if (!isNil(obj.bonds)) { | ||
// If bonds are invalid, throw them out but still keep the atoms | ||
@@ -20,3 +21,3 @@ if (!validateBonds(obj.atoms, obj.bonds)) { | ||
} | ||
if (obj.cube) { | ||
if (!isNil(obj.cube)) { | ||
// If cube data is invalid, throw it out but still keep the rest | ||
@@ -27,2 +28,8 @@ if (!validateCube(obj.cube)) { | ||
} | ||
if (!isNil(obj.vibrations)) { | ||
// If vibration data is invalid, throw it out but still keep the rest | ||
if (!validateVibrations(obj.atoms, obj.vibrations)) { | ||
obj.vibrations = undefined; | ||
} | ||
} | ||
return true; | ||
@@ -44,3 +51,3 @@ } | ||
let nAtoms: number = numberOfAtoms(atoms); | ||
if (bonds.order) { | ||
if (!isNil(bonds.order)) { | ||
if (bonds.order.length * 2 !== bonds.connections.index.length) { | ||
@@ -69,4 +76,29 @@ return false; | ||
function validateVibrations(atoms: IAtoms, vibrations: IVibrations) : boolean { | ||
if (isNil(vibrations.modes)) { | ||
return false; | ||
} | ||
let nModes: number = vibrations.modes.length; | ||
if (vibrations.frequencies && vibrations.frequencies.length !== nModes) { | ||
return false; | ||
} | ||
if (!isNil(vibrations.intensities) && vibrations.intensities.length !== nModes) { | ||
return false; | ||
} | ||
if (!isNil(vibrations.eigenVectors)) { | ||
if (vibrations.eigenVectors.length !== nModes) { | ||
return false; | ||
} | ||
let nAtoms: number = numberOfAtoms(atoms); | ||
for (let eigenVector of vibrations.eigenVectors) { | ||
if (eigenVector.length !== nAtoms * 3) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
function numberOfAtoms(atoms: IAtoms) : number { | ||
if (atoms.elements.number && atoms.elements.symbol) { | ||
if (!isNil(atoms.elements.number) && !isNil(atoms.elements.symbol)) { | ||
if (atoms.elements.number.length !== atoms.elements.symbol.length) { | ||
@@ -76,5 +108,5 @@ return -1; | ||
return atoms.elements.number.length; | ||
} else if (atoms.elements.number) { | ||
} else if (!isNil(atoms.elements.number)) { | ||
return atoms.elements.number.length; | ||
} else if (atoms.elements.symbol) { | ||
} else if (!isNil(atoms.elements.symbol)) { | ||
return atoms.elements.symbol.length; | ||
@@ -81,0 +113,0 @@ } else { |
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
19461
405
3
+ Added@types/lodash-es@^4.17.0
+ Addedlodash-es@^4.17.10
+ Added@openchemistry/types@0.1.0(transitive)
+ Added@types/lodash@4.17.13(transitive)
+ Added@types/lodash-es@4.17.12(transitive)
+ Addedlodash-es@4.17.21(transitive)
- Removed@openchemistry/types@0.0.6(transitive)
Updated@openchemistry/types@^0.1.0