@openchemistry/utils
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -6,2 +6,18 @@ # Change Log | ||
<a name="0.5.0"></a> | ||
# [0.5.0](https://github.com/OpenChemistry/oc-web-components/compare/@openchemistry/utils@0.4.2...@openchemistry/utils@0.5.0) (2018-09-17) | ||
### Bug Fixes | ||
* **utils:** Add warning if cjson validation fails ([d0ab0b8](https://github.com/OpenChemistry/oc-web-components/commit/d0ab0b8)) | ||
### Features | ||
* **utils:** Add orbitals to cjson validation ([4dcb998](https://github.com/OpenChemistry/oc-web-components/commit/4dcb998)) | ||
<a name="0.4.2"></a> | ||
@@ -8,0 +24,0 @@ ## [0.4.2](https://github.com/OpenChemistry/oc-web-components/compare/@openchemistry/utils@0.4.1...@openchemistry/utils@0.4.2) (2018-09-13) |
@@ -8,2 +8,3 @@ import { isNil } from "lodash-es"; | ||
if (!validateAtoms(obj.atoms)) { | ||
console.warn('Invalid CJSON data, missing atoms'); | ||
return false; | ||
@@ -14,2 +15,3 @@ } | ||
if (!validateBonds(obj.atoms, obj.bonds)) { | ||
console.warn('Invalid CJSON data, discarding bonds'); | ||
obj.bonds = undefined; | ||
@@ -21,2 +23,3 @@ } | ||
if (!validateCube(obj.cube)) { | ||
console.warn('Invalid CJSON data, discarding cube'); | ||
obj.cube = undefined; | ||
@@ -28,5 +31,13 @@ } | ||
if (!validateVibrations(obj.atoms, obj.vibrations)) { | ||
console.warn('Invalid CJSON data, discarding vibrations'); | ||
obj.vibrations = undefined; | ||
} | ||
} | ||
if (!isNil(obj.molecularOrbitals)) { | ||
// If orbitals data is invalid, throw it out but still keep the rest | ||
if (!validateMolecularOrbitals(obj.molecularOrbitals)) { | ||
console.warn('Invalid CJSON data, discarding molecular orbitals'); | ||
obj.molecularOrbitals = undefined; | ||
} | ||
} | ||
return true; | ||
@@ -95,2 +106,13 @@ } | ||
} | ||
function validateMolecularOrbitals(mo) { | ||
// There was a typo in avogadrolibs code... | ||
if (isNil(mo.occupations) && !isNil(mo.occpupations)) { | ||
mo.occupations = mo.occpupations; | ||
return false; | ||
} | ||
if (mo.energies.length === mo.numbers.length && mo.energies.length === mo.occupations.length) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function numberOfAtoms(atoms) { | ||
@@ -97,0 +119,0 @@ if (!isNil(atoms.elements.number) && !isNil(atoms.elements.symbol)) { |
{ | ||
"name": "@openchemistry/utils", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "Utilities to validate and convert cjson chemical data", | ||
@@ -25,3 +25,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@openchemistry/types": "^0.6.2", | ||
"@openchemistry/types": "^0.7.0", | ||
"@types/lodash-es": "^4.17.1", | ||
@@ -28,0 +28,0 @@ "typescript": "^3.0.3" |
@@ -1,2 +0,2 @@ | ||
import { IChemJson, IAtoms, IBonds, ICube, IVibrations } from '@openchemistry/types'; | ||
import { IChemJson, IAtoms, IBonds, ICube, IVibrations, IMolecularOrbitals } from '@openchemistry/types'; | ||
import { isNil } from "lodash-es"; | ||
@@ -12,2 +12,3 @@ | ||
if (!validateAtoms(obj.atoms)) { | ||
console.warn('Invalid CJSON data, missing atoms'); | ||
return false; | ||
@@ -18,2 +19,3 @@ } | ||
if (!validateBonds(obj.atoms, obj.bonds)) { | ||
console.warn('Invalid CJSON data, discarding bonds'); | ||
obj.bonds = undefined; | ||
@@ -25,2 +27,3 @@ } | ||
if (!validateCube(obj.cube)) { | ||
console.warn('Invalid CJSON data, discarding cube'); | ||
obj.cube = undefined; | ||
@@ -32,5 +35,13 @@ } | ||
if (!validateVibrations(obj.atoms, obj.vibrations)) { | ||
console.warn('Invalid CJSON data, discarding vibrations'); | ||
obj.vibrations = undefined; | ||
} | ||
} | ||
if (!isNil(obj.molecularOrbitals)) { | ||
// If orbitals data is invalid, throw it out but still keep the rest | ||
if (!validateMolecularOrbitals(obj.molecularOrbitals)) { | ||
console.warn('Invalid CJSON data, discarding molecular orbitals'); | ||
obj.molecularOrbitals = undefined; | ||
} | ||
} | ||
return true; | ||
@@ -101,2 +112,14 @@ } | ||
function validateMolecularOrbitals(mo: IMolecularOrbitals) : boolean { | ||
// There was a typo in avogadrolibs code... | ||
if (isNil(mo.occupations) && !isNil((mo as any).occpupations)) { | ||
mo.occupations = (mo as any).occpupations; | ||
return false; | ||
} | ||
if (mo.energies.length === mo.numbers.length && mo.energies.length === mo.occupations.length) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function numberOfAtoms(atoms: IAtoms) : number { | ||
@@ -103,0 +126,0 @@ if (!isNil(atoms.elements.number) && !isNil(atoms.elements.symbol)) { |
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
39747
916