Skip to content

Commit

Permalink
Replace species by kind
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Oct 31, 2024
1 parent ecd7b28 commit 8d0d277
Show file tree
Hide file tree
Showing 24 changed files with 282 additions and 301 deletions.
12 changes: 6 additions & 6 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, Kind, 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.Kind = Kind;

async function fetchFile(filename) {
const response = await fetch(`datas/${filename}`);
Expand Down Expand Up @@ -68,8 +68,8 @@ async function updateAtoms(filename, fileContent = null) {
const atomsList = parseXYZ(structureData);
// 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" }, "kind");
// atomsList[0].newAttribute("radii", { C: 1.5, H: 1.0, O: 1.5, S: 1.5 }, "kind");
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 @@ -232,12 +232,12 @@ async function updateAtoms(filename, fileContent = null) {
editor.anyMesh.fromSettings(data);
editor.anyMesh.drawMesh();
break;
case "species":
case "kinds":
editor.clear();
filename = "c2h6so.xyz";
structureData = fileContent || (await fetchFile(filename));
atoms = parseXYZ(structureData);
atoms[0].addSpecies("C1", "C");
atoms[0].addKind("C1", "C");
atoms[0].symbols[3] = "C1";
editor.avr.atoms = atoms;
// editor.avr.bondManager.settings[1].color1 = "blue";
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1>WEAS (Web Environment For Atomistic Structures)</h1>
<option value="mesh_primitives_settings.json">Primitives instance</option>
<option value="any_mesh_settings.json">Any Mesh</option>
<option value="phonon">Phonon</option>
<option value="species">Species</option>
<option value="kinds">Kinds</option>
</select>

<!-- Add Upload Button Here -->
Expand Down
31 changes: 15 additions & 16 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 kinds and attributes.


Example:
Expand All @@ -16,42 +16,42 @@ 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
Kind
-------
Why do we use species instead of elements? Because of we want to store different properties for the same element:
Why do we use kinds 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 kind has:

- symbol: the name of the species, e.g. 'O', 'H1', 'Fe_up', etc.
- symbol: the name of the kind, 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.

One can define the species explicitly using the `species` attribute.
One can define the kinds explicitly using the `kinds` attribute.

.. code-block:: javascript
const myAtoms = new Atoms({
symbols: ['O', 'H1', 'H2'], // symbols of the atoms
species: {'H1': 'H', 'H2': 'H'}, // Defining the species
kinds: {'H1': 'H', 'H2': 'H'}, // Defining the kinds
});
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.
- `kind`: store data that is specific to each kind, 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},
'kind': {'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 Kind Manipulation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Cell and Boundary Conditions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -100,7 +99,7 @@ Information and Export
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- getAtomsCount()
- getSpeciesCount()
- getKindsCount()
- getCellLengthsAndAngles()
- calculateFractionalCoordinates()
- toDict()
Expand Down
6 changes: 3 additions & 3 deletions docs/source/atoms/color.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Supported style are:


-----------------------------
Custom color for each species
Custom color for each kind
-----------------------------
Use can set custom color for each species. The color can be in the form of hex code or color name.
Use can set custom color for each kind. The color can be in the form of hex code or color name.


.. code-block:: javascript
Expand All @@ -35,7 +35,7 @@ Use can set custom color for each species. The color can be in the form of hex c
weas.avr.drawModels()
.. image:: ../_static/images/example_color_by_species.png
.. image:: ../_static/images/example_color_by_kind.png
:width: 6cm


Expand Down
2 changes: 1 addition & 1 deletion docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Here is the result of the above code:
Features
--------

- **Structure Manipulation**: Enables manipulation of the structure, such as adding, removing, translating, rotating atoms and modifying species, and cell parameters.
- **Structure Manipulation**: Enables manipulation of the structure, such as adding, removing, translating, rotating atoms and modifying kind, and cell parameters.

- **Customizable Appearance**: Allows customization of atom and bond appearances, including colors, sizes, and visibility, polyhedra, and unit cell.

Expand Down
6 changes: 3 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,7 @@ 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);
this.atoms.addKind(element);
this.atoms.addAtom(atom);
// this.logger.debug("atoms: ", this.atoms);

Expand All @@ -598,7 +598,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 8d0d277

Please sign in to comment.