Nucleus
Nucleus is the core of an atom. Basically, it is the part of the atom that
remains if you remove all the electrons. In Chemist, Nucleus class extends the
PointCharge class with mass (mass()
) and atomic number (Z
) while
inheriting the coordinates (x()
, y()
, z()
, coord()
) and charge
(charge()
). In this tutorial, we will learn how to create a Nucleus object,
how to access its properties, and how to manipulate them.
Construction
There are four different ways to create a Nucleus object. #. The first one is the default constructor, which creates a Nucleus object centered at the origin (0.0, 0.0, 0.0) with zero mass and charge. #. The second one is the constructor that takes the name of the nucleus as a string literal, its atomic number as an integer and its mass as a float. This constructor creates the Nucleus object at the origin with charge equal to the atomic number converted to a float. #. The third constructor takes additionally the x, y, z positions of the nucleus as floats. #. The fourth constructor takes additionally the charge of the Nucleus object. Note that this is a point charge assigned to the Nucleus object, no charged particles added or removed.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "catch.hpp"
#include <cereal/archives/binary.hpp>
#include <chemist/nucleus/nucleus.hpp>
#include <iostream>
#include <sstream>
#include <string>
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
Properties
Nucleus class provides access to the following properties: - name: name of the nucleus - Z: atomic number of the nucleus - mass: mass of the nucleus in atomic units - x: x-coordinate of the nucleus - y: y-coordinate of the nucleus - z: z-coordinate of the nucleus - charge: charge of the nucleus in atomic units
int nucleus_example() {
// Creating Nucleus objects using different constructors
// Default constructor, properties are initialized to:
// name = '', atomic_number = 0, mass = 0.0
// x = 0.0, y = 0.0, z = 0.0, charge = 0.0
Nucleus n0;
// Constructor with name, atomic number, and mass
// Coordinates are initialized to: x = 0.0, y = 0.0, z = 0.0
// Charge is initialized to atomic_number cast to a double, i.e., 1.0
Nucleus n1("H", 1ul, 1.0079);
// Constructor with name, atomic number, mass, and x, y, z coordinates
// Charge is initialized to atomic_number cast to a double, i.e., 1.0
Nucleus n2("H", 1ul, 1.0079, 0.0, 0.0, 0.0);
// Accessing the properties of a Nucleus object
// Accessing the name
std::string n1_name = n1.name();
REQUIRE(n1_name == "H");
REQUIRE(n0.name() == "");
// Accessing the atomic number
std::size_t n1_Z = n1.Z();
REQUIRE(n1_Z == 1ul);
REQUIRE(n0.Z() == 0ul);
// Accessing the mass
double n1_mass = n1.mass();
REQUIRE(n1_mass == 1.0079);
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import chemist
import unittest
class TestStringMethods(unittest.TestCase):
def testAtom(self):
# Creating Nucleus objects using different constructors
n0 = chemist.Nucleus()
n1 = chemist.Nucleus("H", 1, 1.0079)
n2 = chemist.Nucleus("H", 1, 1.0079, 0.0, 0.0, 0.0)
Modifying properties
Users can modify all the properties of a Nucleus object. Below, you can find how you can modify the properties of a Nucleus object and compare two Nucleus objects.
double n1_y = n1.y();
double n1_z = n1.z();
REQUIRE(n1_x == 0.0);
REQUIRE(n0.x() == 0.0);
REQUIRE(n1_y == 0.0);
REQUIRE(n0.y() == 0.0);
REQUIRE(n1_z == 0.0);
REQUIRE(n0.z() == 0.0);
// Accessing the charge
double n1_charge = n1.charge();
REQUIRE(n1_charge == 1.0);
REQUIRE(n0.charge() == 0.0);
assert n0.Z == 0
assert n1.Z == 1
# Accessing the mass
assert n0.mass == 0.0
assert n1.mass == 1.0079
# Accessing the position
assert n0.x == 0.0