atom

A module containing the Atom class and some associated functions.

The Atom class is used to represent an atom in a molecule. It contains the following attributes:

  • name: the name of the atom (e.g. ‘C’)

  • element: the element of the atom (e.g. ‘C’)

The atomic number and mass are automatically determined from the name or symbol of the atom. The name and symbol are automatically determined from the atomic number. The name is the symbol in lower case.

Summary

Classes:

Atom

A class used to represent an atom in a molecule.

Reference

class Atom(
name: str | int | Element,
element_id: int | str | None = None,
use_guess_element: bool = True,
**_kwargs,
)[source]

Bases: object

A class used to represent an atom in a molecule.

There are three ways to initialize an Atom object:

  1. By giving the name of the atom_type (e.g. ‘C1’) If use_guess_element is True (default), the atom_type name has to be a valid element symbol (e.g. ‘C’). If use_guess_element is False, the atom_type name can be anything and an empty element is created.

  2. By giving the name of the atom_type (e.g. ‘C1’) and the id of the atom_type (e.g. 6). The id can be either an integer (atomic number) or a string (element symbol).

  3. By giving the id of the atom_type (e.g. 6). The id can be either an integer (atomic number) or a string (element symbol).

Examples

>>> atom = Atom('C1') # use_guess_element is True by default
Traceback (most recent call last):
    ...
ElementNotFoundError: Id C1 is not a valid element identifier.
>>> atom = Atom('C1', use_guess_element=False)
>>> (atom.name, atom.element)
('C1', Element(None, None, None))
>>> atom = Atom('C1', 'C')
>>> (atom.name, atom.element)
('C1', Element(c, 6, 12.0107))
>>> atom = Atom('C1', 6)
>>> (atom.name, atom.element)
('C1', Element(c, 6, 12.0107))
>>> atom = Atom(6)
>>> (atom.name, atom.element)
('c', Element(c, 6, 12.0107))
>>> atom = Atom('C')
>>> (atom.name, atom.element)
('C', Element(c, 6, 12.0107))

Constructs all the necessary attributes for the Atom object.

If use_guess_element is True, the symbol, atomic number and mass are determined from the name of the atom_type. If use_guess_element is False, the symbol, atomic number and mass are set to None, meaning that an empty element is created (Element()).

Parameters:
  • name (str | int | Element) – The name of the atom_type (e.g. ‘C1’) If this parameter is an integer, it is interpreted as the atomic number of the element symbol and cannot be used together with the id parameter. If the parameter is an Element object, the element is set to this object and no other parameters are used.

  • element_id (int | str, optional) – The atomic number or element symbol of the atom_type (e.g. 6 or ‘C’) If his parameter is not given, the name parameter is used to determine the element type of the atom_type.

  • use_guess_element (bool, optional) – Whether to use the guess_element function to determine the element type of the atom_type by its name, by default True

  • **_kwargs – Additional keyword arguments that are not used by the function but by the runtime type checker.

Raises:
  • PQValueError – If the name of the atom_type is an Element object and the id is given.

  • AtomError – If the name of the atom_type is an integer and the id is given.

__eq__(other: Any) bool[source]

Checks whether the Atom is equal to another Atom.

Parameters:

other (Any) – The other Atom to compare to.

Returns:

True if the Atom is equal to the other Atom, False otherwise.

Return type:

bool

__repr__() str[source]

Returns a representation of the Atom.

Returns:

A representation of the Atom.

Return type:

str

__str__() str[source]

Returns a string representation of the Atom.

Returns:

A string representation of the Atom.

Return type:

str

property atomic_number: int | None

The atomic number of the element (e.g. 6)

Type:

int | None

property element: Element

The element type of the atom

Type:

Element

property element_name: str

The name of the element (e.g. ‘Carbon’)

Type:

str

logger = <CustomLogger PQAnalysis.Atom (INFO)>
property mass: Real | None

The mass of the element (e.g. 12.011)

Type:

Real | None

property name: str

The name of the atom_type (e.g. ‘C1’)

Type:

str

property symbol: str | None

The symbol of the element (e.g. ‘c’)

Type:

str

class Atoms

A type hint for a list of atoms

alias of TypeVar(‘Atoms’, bound=list[PQAnalysis.core.Atom])