Skip to content

Commit

Permalink
Use plural and singular form of species in the code (#39)
Browse files Browse the repository at this point in the history
Even though the word `species` is both singular and plural, in the code, we use `specie` for the singular and `species` for the plural.
  • Loading branch information
superstar54 authored Oct 31, 2024
1 parent ecd7b28 commit 48dfcaf
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 263 deletions.
11 changes: 6 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { WEAS, Atoms, Species, parseXYZ, parseCIF, parseCube } from "../src/index.js"; // Adjust the path as necessary
import { WEAS, Atoms, Specie, parseXYZ, parseCIF, parseCube } from "../src/index.js"; // Adjust the path as necessary
import * as THREE from "three";

window.THREE = THREE;
window.WEAS = WEAS;
window.Atoms = Atoms;
window.Species = Species;
window.Specie = Specie;

async function fetchFile(filename) {
const response = await fetch(`datas/${filename}`);
Expand Down Expand Up @@ -66,10 +66,11 @@ async function updateAtoms(filename, fileContent = null) {
filename = "c2h6so.xyz";
structureData = fileContent || (await fetchFile(filename));
const atomsList = parseXYZ(structureData);
console.log("atomsList: ", atomsList);
// atomsList[0].newAttribute("moment", [1, 1, 1, 1, 1, -1, -1, -1, -1, -1], "atom");
// atomsList[0].newAttribute("charge", [-1, 0.5, 1, 0.5, 0.3, 0.2, 2, 1, 0, -0.5], "atom");
// atomsList[0].newAttribute("color", { C: "##eb4034", H: "#b434eb", O: "#34eb77", S: "#FFFF00" }, "species");
// atomsList[0].newAttribute("radii", { C: 1.5, H: 1.0, O: 1.5, S: 1.5 }, "species");
// atomsList[0].newAttribute("color", { C: "##eb4034", H: "#b434eb", O: "#34eb77", S: "#FFFF00" }, "specie");
// atomsList[0].newAttribute("radii", { C: 1.5, H: 1.0, O: 1.5, S: 1.5 }, "specie");
editor.avr.atoms = atomsList;
// editor.avr.bondManager.settings[1].color1 = "blue";
// editor.avr.VFManager.addSetting({ origins: "positions", vectors: "movement", color: "#ff0000", radius: 0.1 });
Expand Down Expand Up @@ -237,7 +238,7 @@ async function updateAtoms(filename, fileContent = null) {
filename = "c2h6so.xyz";
structureData = fileContent || (await fetchFile(filename));
atoms = parseXYZ(structureData);
atoms[0].addSpecies("C1", "C");
atoms[0].addSpecie("C1", "C");
atoms[0].symbols[3] = "C1";
editor.avr.atoms = atoms;
// editor.avr.bondManager.settings[1].color1 = "blue";
Expand Down
23 changes: 11 additions & 12 deletions docs/source/atoms/atoms.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Atoms
=========
The Atoms object represents a collection of atoms. It is used to store the positions, species, and other properties of the atoms. The sytax is very similar to ASE `Atoms <https://wiki.fysik.dtu.dk/ase/ase/atoms.html#module-ase.atoms>`_ object. However, there are also some key differences regarding the species and attributes.
The Atoms object represents a collection of atoms. It is used to store the positions, symbols, and other properties of the atoms. The sytax is very similar to ASE `Atoms <https://wiki.fysik.dtu.dk/ase/ase/atoms.html#module-ase.atoms>`_ object. However, there are also some key differences regarding the species and attributes.


Example:
Expand All @@ -16,16 +16,16 @@ Example:
In this example, an Atoms object is created to represent a water molecule within a cubic unit cell with periodic boundaries. The object includes definitions for the symbols, positions of the atoms.

Species
Specie
-------
Why do we use species instead of elements? Because of we want to store different properties for the same element:

- such as: colors, bonds, etc.
- In DFT calculation, different potentials, basis sets, charge, magnetic moment, etc.

A species has:
A specie has:

- symbol: the name of the species, e.g. 'O', 'H1', 'Fe_up', etc.
- symbol: the name of the specie, e.g. 'O', 'H1', 'Fe_up', etc.
- element: the element symbol, e.g. 'O', 'H', 'Fe', etc.
- number: the atomic number of the element, e.g. 8, 1, 26, etc.

Expand All @@ -42,16 +42,16 @@ Attributes and domain
----------------------
One can store additional data in the Atoms object using the `attributes`. The `attributes` has two domains:

- `atoms`: store data that is specific to each atom, such as the charge or force.
- `species`: store data that is specific to each species, such as the mass, color, or radius.
- `atom`: store data that is specific to each atom, such as the charge or force.
- `specie`: store data that is specific to each specie, such as the mass, color, or radius.


.. code-block:: javascript
attributes: {'atoms': {'charge': [0, 0, 0],
attributes: {'atom': {'charge': [0, 0, 0],
'force': [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
},
'species': {'mass': {'O': 15.999, 'H': 1.008},
'specie': {'mass': {'O': 15.999, 'H': 1.008},
"color", {C: "red", H: "#b434eb", O: "#34eb77", S: "#FFFF00" },
"radius", {C: 0.77, H: 0.37, O: 0.66, S: 1.04},
},
Expand All @@ -63,13 +63,12 @@ Methods
The Atoms object has a number of methods that can be used to manipulate the data. These include methods to:


Atomic and Species Manipulation
Atomic and Specie Manipulation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- addSpecies(symbol, element = null)
- addSpecie(symbol, element = null)
- addAtom(atom)
- removeAtom(index)
- replaceAtoms(indices, newSpeciesSymbol)
- replaceAtoms(indices, newSpecieSymbol)

Cell and Boundary Conditions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
9 changes: 6 additions & 3 deletions src/atoms/AtomsViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class AtomsViewer {
// Remove labels
this.ALManager.settings = [];
} else if (newValue === "Symbol") {
this.ALManager.settings = [{ origins: "positions", texts: "species" }];
this.ALManager.settings = [{ origins: "positions", texts: "symbols" }];
} else if (newValue === "Index") {
this.ALManager.settings = [{ origins: "positions", texts: "index" }];
}
Expand Down Expand Up @@ -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.addSpecies(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);

Expand All @@ -598,7 +601,7 @@ class AtomsViewer {
}
const copied_atoms = this.atoms.getAtomsByIndices(indices);
this.logger.debug("copied_atoms: ", copied_atoms);
this.atoms.addToSelf(copied_atoms);
this.atoms.add(copied_atoms);
this.logger.debug("atoms: ", this.atoms);

// also copy the properties, e.g. modelStyles, that are associated with the copied atoms
Expand Down
Loading

0 comments on commit 48dfcaf

Please sign in to comment.