diff --git a/.github/workflows/Coverage.yml b/.github/workflows/Coverage.yml index 6467ef6e..bebd6a8b 100644 --- a/.github/workflows/Coverage.yml +++ b/.github/workflows/Coverage.yml @@ -29,7 +29,7 @@ jobs: # so ignore any failure here run: npm run cover continue-on-error: true - + timeout-minutes: 60 - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/src/parsers/VASP.ts b/src/parsers/VASP.ts index c76ace5f..097c6252 100644 --- a/src/parsers/VASP.ts +++ b/src/parsers/VASP.ts @@ -3,6 +3,7 @@ import { Matrix3 } from "../WebGL"; import { assignBonds } from "./utils/assignBonds"; import { ParserOptionsSpec } from "./ParserOptionsSpec"; +import { AtomSpec } from "specs"; /** * @param {string} @@ -58,26 +59,23 @@ export function VASP(str: string, options: ParserOptionsSpec = {}) { matrix.multiplyScalar(lattice.length); atoms.modelData = [{ symmetries: [], cryst: { matrix: matrix } }]; - var atomSymbols = lines[5] - .replace(/\s+/, "") - .replace(/\s+$/, "") - .split(/\s+/); + var atomSymbols = lines[5].trim().split(/\s+/); var atomSpeciesNumber = new Int16Array( - (lines[6] as any).replace(/^\s+/, "").split(/\s+/) + lines[6].trim().split(/\s+/) as any ); - var vaspMode = lines[7].replace(/\s+/, ""); + var vaspMode = lines[7].trim(); var selective = false if (vaspMode.match(/S/)) { selective = true - vaspMode = lines[8].replace(/\s+/, ""); + vaspMode = lines[8].trim(); } - if (vaspMode.match(/C/)) { + if (vaspMode.toLowerCase()[0] == "c") { vaspMode = "cartesian"; - } else if (vaspMode.match(/D/)) { + } else if (vaspMode.toLowerCase()[0] == "d") { vaspMode = "direct"; - } else { + } else { console.log( "Warning: Unknown vasp mode in POSCAR file: mode must be either C(artesian) or D(irect)" ); @@ -104,10 +102,10 @@ export function VASP(str: string, options: ParserOptionsSpec = {}) { var atomSymbol = atomSymbols[i]; for (var j = 0, atomLen = atomSpeciesNumber[i]; j < atomLen; j++) { var coords = new Float32Array( - (lines[atomCounter + j] as any).replace(/^\s+/, "").split(/\s+/) + lines[atomCounter + j].trim().split(/\s+/) as any ); - var atom: Record = {}; + var atom: AtomSpec = {}; (atom.elem as any) = atomSymbol; if (vaspMode == "cartesian") { atom.x = lattice.length * coords[0]; diff --git a/tests/auto/data/mg.vasp b/tests/auto/data/mg.vasp new file mode 100644 index 00000000..d58a57a2 --- /dev/null +++ b/tests/auto/data/mg.vasp @@ -0,0 +1,10 @@ +MgO Fm-3m (No. 225) +1.0 + 2.606553 0.000000 1.504894 + 0.868851 2.457482 1.504894 + 0.000000 0.000000 3.009789 + Mg O + 1 1 +direct + 0.000000 0.000000 0.000000 Mg + 0.500000 0.500000 0.500000 O diff --git a/tests/auto/tests/vaspex.js b/tests/auto/tests/vaspex.js new file mode 100644 index 00000000..0a2f4845 --- /dev/null +++ b/tests/auto/tests/vaspex.js @@ -0,0 +1,10 @@ + + +$.get('data/mg.vasp', function(v) { + let m = viewer.addModel(v, 'vasp'); + + viewer.addStyle('sphere'); + + viewer.zoomTo(); + viewer.render(); +}); diff --git a/tests/glcheck/reference-images/tests-glcheck-render-tests-vaspex.html.png b/tests/glcheck/reference-images/tests-glcheck-render-tests-vaspex.html.png new file mode 100644 index 00000000..15b0aa7f Binary files /dev/null and b/tests/glcheck/reference-images/tests-glcheck-render-tests-vaspex.html.png differ