diff --git a/docs/source/atoms/color.rst b/docs/source/atoms/color.rst index 16f9f49..46434fc 100644 --- a/docs/source/atoms/color.rst +++ b/docs/source/atoms/color.rst @@ -21,9 +21,9 @@ Supported style are: ----------------------------- -Custom color for each specie +Custom color for each species ----------------------------- -Use can set custom color for each specie. The color can be in the form of hex code or color name. +Use can set custom color for each species. The color can be in the form of hex code or color name. .. code-block:: javascript diff --git a/src/atoms/AtomsViewer.js b/src/atoms/AtomsViewer.js index 1338677..013d580 100644 --- a/src/atoms/AtomsViewer.js +++ b/src/atoms/AtomsViewer.js @@ -572,7 +572,10 @@ class AtomsViewer { addAtom(element, position = { x: 0, y: 0, z: 0 }) { // Remove the selected atoms from the scene and data const atom = new Atom(element, [position.x, position.y, position.z]); - this.atoms.addSpecie(element); + // if element is not in the species, add it to the species + if (!this.atoms.species[element]) { + this.atoms.addSpecie(element); + } this.atoms.addAtom(atom); // this.logger.debug("atoms: ", this.atoms); diff --git a/src/atoms/atoms.js b/src/atoms/atoms.js index 38409e7..a17c8e4 100644 --- a/src/atoms/atoms.js +++ b/src/atoms/atoms.js @@ -246,7 +246,6 @@ class Atoms { ...this.attributes["specie"][name], }; } - return result; } multiply(mx, my, mz) { diff --git a/tests/atoms.test.mjs b/tests/atoms.test.mjs index bf8c889..915dcea 100644 --- a/tests/atoms.test.mjs +++ b/tests/atoms.test.mjs @@ -1,32 +1,30 @@ -import { Species, Atom, Atoms } from "../dist/weas.mjs"; +import { Specie, Atom, Atoms } from "../dist/weas.mjs"; -describe("Species class", () => { - it("creates a new Species instance correctly", () => { - const species = new Species("C1", "C"); - expect(species.symbol).toBe("C1"); +describe("Specie class", () => { + it("creates a new Specie instance correctly", () => { + const species = new Specie("C"); expect(species.element).toBe("C"); expect(species.number).toBe(6); }); - it("creates a new Species use only symbol", () => { - const species = new Species("C"); - expect(species.symbol).toBe("C"); + it("creates a new Specie use only symbol", () => { + const species = new Specie("C"); expect(species.element).toBe("C"); expect(species.number).toBe(6); }); it("throws an error when adding an unknown species", () => { const value = "Unknown"; expect(() => { - const species = new Species("Unknown"); // This species does not exist in the atoms instance - }).toThrowError(`Element '${value}' is wrong.`); + const species = new Specie("Unknown"); // This species does not exist in the atoms instance + }).toThrowError(`Element '${value}' is invalid.`); }); }); describe("Atom class", () => { it("creates a new Atom instance correctly", () => { - const species = "H"; // Assuming this refers to an existing species + const symbol = "H"; // Assuming this refers to an existing symbol const position = [1.0, 2.0, 3.0]; - const atom = new Atom(species, position); - expect(atom.species).toBe(species); + const atom = new Atom(symbol, position); + expect(atom.symbol).toBe(symbol); expect(atom.position).toEqual(position); }); }); @@ -53,7 +51,7 @@ describe("Atoms class", () => { it("adds a species correctly", () => { atoms.addSpecie("H"); expect(atoms.species).toHaveProperty("H"); - expect(atoms.species["H"]).toEqual(new Species("H")); + expect(atoms.species["H"]).toEqual(new Specie("H")); }); // Add more tests for other methods like setCell, addAtom, removeAtom, etc. diff --git a/tests/e2e/gui.spec.js-snapshots/Edit-Duplicate-Atoms-1-chromium-linux.png b/tests/e2e/gui.spec.js-snapshots/Edit-Duplicate-Atoms-1-chromium-linux.png index e1063ef..1b5e257 100644 Binary files a/tests/e2e/gui.spec.js-snapshots/Edit-Duplicate-Atoms-1-chromium-linux.png and b/tests/e2e/gui.spec.js-snapshots/Edit-Duplicate-Atoms-1-chromium-linux.png differ diff --git a/tests/parserXYZ.test.mjs b/tests/parserXYZ.test.mjs index 32f53cd..6737087 100644 --- a/tests/parserXYZ.test.mjs +++ b/tests/parserXYZ.test.mjs @@ -1,4 +1,4 @@ -import { parseXYZ, Species } from "../dist/weas.mjs"; +import { parseXYZ, Specie } from "../dist/weas.mjs"; describe("parseXYZ", () => { it("parses valid XYZ data correctly", () => { @@ -15,8 +15,8 @@ H 0.000000 0.757160 0.482080 expect(atoms).toBeDefined(); expect(atoms.species).toHaveProperty("H"); expect(atoms.species).toHaveProperty("O"); - expect(atoms.species["H"]).toEqual(new Species("H")); - expect(atoms.species["O"]).toEqual(new Species("O")); + expect(atoms.species["H"]).toEqual(new Specie("H")); + expect(atoms.species["O"]).toEqual(new Specie("O")); expect(atoms.positions.length).toBe(3); expect(atoms.symbols).toEqual(["O", "H", "H"]); console.log(atoms.positions[0]);