Threads, errors, elements and units¶
Threads and indices¶
get_num_threads ¶
Number of threads used by compiled kernels.
Returns:
| Type | Description |
|---|---|
int64
|
The current setting. Defaults to the number of logical CPUs this
process may use, or to the |
set_num_threads ¶
Set the number of threads used by compiled kernels.
The setting is global to the process and takes effect at the next computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int32
|
Number of threads, at least 1. |
required |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If |
num_threads ¶
Use n threads inside a with block.
The previous setting is restored when the block exits, also on error.
Like set_num_threads, the setting is global to the process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int32
|
Number of threads, at least 1. |
required |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If |
CancelToken ¶
Flag for stopping a running computation from another thread.
Pass the token to a computation that accepts cancel=. Calling
cancel from any thread makes that computation stop at the next
chunk of work and raise mdapy.errors.Cancelled.
index_dtype
module-attribute
¶
numpy.dtype of atom indices in results such as neighbor lists: int32, or
int64 when MDAPY was built with -Ccmake.define.MDAPY_INDEX64=ON.
Results¶
Result
dataclass
¶
Results of an analysis: immutable, with read-only arrays.
System.with_columns(result) adds the per-atom values of
columns to a system.
Versions¶
show_versions ¶
Print the versions of MDAPY, Python and the packages MDAPY depends on, and the processor, memory and GPU of this machine, to paste into an issue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
text stream
|
Where to print them; the standard output by default. |
None
|
Errors¶
errors ¶
Exception types raised by mdapy.
MdapyError ¶
Bases: Exception
Base class of every exception raised by mdapy.
InvalidParameter ¶
Bases: MdapyError, ValueError
A parameter has a value that MDAPY cannot accept.
The message names the parameter and the accepted values.
MissingProperty ¶
Bases: MdapyError, LookupError
A required per-atom or global property is not present.
UnsupportedFormat ¶
Bases: MdapyError, ValueError
A file format is unknown, or an operation is not supported for it.
FileFormatError ¶
Bases: MdapyError, ValueError
A file does not follow its format.
The message starts with the file name and, when known, the line number.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str or None
|
Name of the file. |
line |
int32 or None
|
Line number, counting from 1. |
Cancelled ¶
Bases: MdapyError
A computation was stopped through a mdapy.CancelToken.
CalculationFailed ¶
Bases: MdapyError, RuntimeError
An external program behind a calculator, such as VASP, did not finish a calculation.
The message holds the end of what the program wrote.
Elements¶
elements ¶
Chemical elements: symbols, atomic numbers, standard atomic weights and radii.
Atomic weights are the IUPAC 2016 standard atomic weights; for elements without stable isotopes they are the mass number of the longest-lived isotope. Covalent radii are those of Cordero et al. (2008), van der Waals radii those of Alvarez (2013).
ATOMIC_MASSES
module-attribute
¶
Standard atomic weights in amu, indexed by atomic number (index 0 is 0.0).
COVALENT_RADII
module-attribute
¶
Covalent radii in Å (Cordero et al. 2008), indexed by atomic number; NaN where there is none.
VDW_RADII
module-attribute
¶
Van der Waals radii in Å (Alvarez 2013), indexed by atomic number; NaN where there is none.
ELEMENT_DTYPE
module-attribute
¶
polars dtype of the element column. Its physical value is the atomic number.
atomic_numbers ¶
Atomic numbers of chemical symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
iterable of str
|
Chemical symbols, case-sensitive ( |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) int64, the atomic numbers, one per symbol. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If a symbol is not a chemical symbol. |
atomic_masses ¶
Standard atomic weights of elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
iterable of str or int32
|
Chemical symbols or atomic numbers (1-118). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) float64, atomic weights in amu, one per element. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If an element is unknown, including |
covalent_radii ¶
Covalent radii of elements (Cordero et al. 2008).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
iterable of str or int32
|
Chemical symbols or atomic numbers. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) float64, radii in Å, one per element. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If an element is unknown or has no covalent radius, as |
vdw_radii ¶
Van der Waals radii of elements (Alvarez 2013).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
iterable of str or int32
|
Chemical symbols or atomic numbers. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N,) float64, radii in Å, one per element. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If an element is unknown or has no van der Waals radius. |
element_from_mass ¶
The element whose standard atomic weight matches a mass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
float64
|
Mass in amu. |
required |
tolerance
|
float64
|
Largest accepted difference in amu between |
0.01
|
candidates
|
iterable of str
|
Chemical symbols to choose from. Default: the elements with at least one stable isotope (H to Bi, without Tc and Pm). Radioactive elements such as Po, whose atomic weights can lie within 0.01 amu of another element's, are only matched when listed here. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Chemical symbol of the matching element. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If no candidate, or more than one, lies within |
Units¶
units ¶
Physical constants and unit conversion factors.
MDAPY works in one unit system: length in Å, energy in eV, time in ps, mass in amu, temperature in K, charge in e, force in eV/Å, stress and pressure in GPa. Every conversion in the package uses the factors defined here.
A factor named A_TO_B converts a value expressed in unit A into unit B
by multiplication.
ELEMENTARY_CHARGE
module-attribute
¶
Elementary charge in C (exact, 2019 SI).
BOLTZMANN_SI
module-attribute
¶
Boltzmann constant in J/K (exact, 2019 SI).
ATOMIC_MASS_UNIT_SI
module-attribute
¶
Atomic mass constant in kg (CODATA 2022).
BOLTZMANN
module-attribute
¶
Boltzmann constant in eV/K.
PLANCK
module-attribute
¶
Planck constant in eV·ps: the energy in eV of a quantum of 1 THz.
EV_PER_A3_TO_GPA
module-attribute
¶
Stress: eV/ų to GPa.
EV_PER_A2_TO_J_PER_M2
module-attribute
¶
Energy per area: eV/Ų to J/m² (equal to N/m).
GPA_A_TO_N_PER_M
module-attribute
¶
Two-dimensional stress: GPa·Å to N/m (exact).
AMU_A2_PER_PS2_TO_EV
module-attribute
¶
Kinetic energy: amu·Å²/ps² to eV (mass times velocity squared).
KJ_PER_MOL_TO_EV
module-attribute
¶
Energy: kJ/mol to eV.
KCAL_PER_MOL_TO_EV
module-attribute
¶
Energy: kcal/mol (thermochemical calorie, 4.184 J) to eV.