exma API

Molecular Dynamics Observables

exma.msd module

Implementation of Mean Square Displacement.

class exma.msd.MeanSquareDisplacement(frames, dt, type_e='all', start=0, stop=-1, step=1)

Bases: MDObservable

Mean Square Displacement (MSD) implementation.

The MSD is a measure of the deviation of the position of an atom with respect to its reference position over time. At each time value t, the MSD is defined as an ensemble average over all atoms to be considered.

Parameters:
  • frames (list) – a list with all the frames of the molecular dynamics trajectory, where each one is an exma.core.AtomicSystem.

  • dt (int or float) – the timestep, how separated the measured frames are from each other, in the corresponding time units

  • type_e (int or str, default="all") – the type of the element for which the msd is going to be calculated, by default it calculates the msd of all atoms.

  • start (int, default=0) – the initial frame

  • stop (int, default=-1) – the last frame, by default -1 means the last

  • step (int, default=1) – the incrementation if it is necessary to skip frames

Notes

The trajectory must be unwrapped outside the simulation cell, if it is wrapped, the image to which it corresponds each atom must be found in the trajectory file.

calculate(box=None)

Calculate the MSD.

Parameters:

box (np.array, default=None) – the lenght of the box in each x, y, z direction, required when the trajectory is in an xyz file.

Returns:

A pd.DataFrame with the time and the msd as columns.

Return type:

pd.DataFrame

plot(ax=None, plot_kws=None)

Plot the calculated MSD.

Parameters:
  • ax (matplotlib.pyplot.Axis, default=None) – current metplotlib axis

  • plot_kws (dict, defualt=None) – additional keyword arguments that are passed and are documented in matplotlib.pyplot.plot.

Returns:

the axis with the plot

Return type:

matplotlib.pyplot.Axis

exma.vacf module

Implementation of Velocity Auto-Correlation Function.

class exma.vacf.VelocityAutocorrelationFunction(frames, dt, type_e='all', start=0, stop=-1, step=1)

Bases: MDObservable

Velocity Autocorrelation Function (VACF) implementation.

The VACF is a measure of the correlation between the velocities of atoms in a molecular system as a function of time. It is calculated by multiplying the velocities of the atoms at a given time by the velocities of the same atoms at a reference time. The average over all atoms is considered.

Parameters:
  • frames (list) – a list with all the frames of the molecular dynamics trajectory, where each one is an exma.core.AtomicSystem and have the velocities defined.

  • dt (int or float) – the timestep, how separated the measured frames are from each other, in the corresponding time units

  • type_e (int or str, default="all") – the type of the element for which the vacf is going to be calculated, by default it calculates the vacf of all atoms.

  • start (int, default=0) – the initial frame

  • stop (int, default=-1) – the last frame, by default -1 means the last

  • step (int, default=1) – the incrementation if it is necessary to skip frames

calculate()

Calculate the VACF.

Returns:

A pd.DataFrame with the time and the vacf as columns.

Return type:

pd.DataFrame

plot(ax=None, plot_kws=None)

Plot the calculated VACF.

Parameters:
  • ax (matplotlib.pyplot.Axis, default=None) – current metplotlib axis

  • plot_kws (dict, defualt=None) – additional keyword arguments that are passed and are documented in matplotlib.pyplot.plot.

Returns:

the axis with the plot

Return type:

matplotlib.pyplot.Axis

exma.rdf module

Radial Distribution Function Calculations.

class exma.rdf.RadialDistributionFunction(frames, type_c='all', type_i='all', start=0, stop=-1, step=1, rmax=10.0, nbin=100, pbc=True)

Bases: MDObservable

Radial Distribution Function (RDF) implementation.

The RDF is a descriptor of the variation of density of a system in function of distance from a reference atom. It gives the probability of finding an atom, relative to an ideal gas, at a given distance.

This microscopic information gives global information about the system, for example, if in an RDF plot the peaks are well defined, it means that the system is behaving like a solid; on the other hand, if the peaks are broadened and decrease in intensity as the distance increases, tending to oscillate around 1, it means that the system behaves like a liquid; a straight line at 1 is an ideal gas.

Parameters:
  • frames (list) – a list with all the frames of the molecular dynamics trajectory, where each one is an exma.core.AtomicSystem.

  • type_c (int or str, default="all") – type of central atoms, by default it computes the total rdf

  • type_i (int or str, default="all") – type of interacting atoms, by default it computes the total rdf

  • start (int, default=0) – the initial frame

  • stop (int, default=-1) – the last frame, by default -1 means the last

  • step (int, default=1) – the incrementation if it is necessary to skip frames

  • rmax (float, default=10.0) – the maximum distance at which to calculate g(r), should not be greater than half of the shortest lenght of the box if pbc are considered

  • nbin (int, default=100) – number of bins in the histogram

  • pbc (bool, default=True) – True if periodic boundary conditions must be considered, False if not.

Notes

The definition of rmax and nbin defines the dr, the width of the histogram as

\[dr = \frac{rmax}{nbin}\]

for example, the default values give dr=0.1.

calculate(box=None)

Calculate the RDF.

Parameters:

box (np.array, default=None) – the lenght of the box in each x, y, z direction, required when the trajectory is in an xyz file.

Returns:

A pd.DataFrame with r and g(r) as columns.

Return type:

pd.DataFrame

plot(ax=None, plot_kws=None)

Plot the calculated RDF.

Parameters:
  • ax (matplotlib.pyplot.Axis, default=None) – current metplotlib axis

  • plot_kws (dict, defualt=None) – additional keyword arguments that are passed and are documented in matplotlib.pyplot.plot.

Returns:

the axis with the plot

Return type:

matplotlib.pyplot.Axis

exma.cn module

Coordination Number Calculations.

class exma.cn.CoordinationNumber(frames, rcut_e, rcut_i=0.0, type_c='all', type_i='all', start=0, stop=-1, step=1, pbc=True)

Bases: MDObservable

Coordination Number (CN) implementation.

The CN, also called ligancy when we are refearing to the first coordination shell, of a central atom is the number of atoms inside the empty sphere defined by an outer and an inner cut-off radius.

Parameters:
  • frames (list) – a list with all the frames of the molecular dynamics trajectory, where each one is an exma.core.AtomicSystem.

  • rcut_e (float) – external cut-off radius of the shell

  • rcut_i (float, default=0.0) – internal cut-off radius of the shell

  • type_c (int or str, default="all") – type of central atoms, by default it computes the total cn

  • type_i (int or str, default="all") – type of interacting atoms, by default it computes the total cn

  • start (int, default=0) – the initial frame

  • stop (int, default=-1) – the last frame, by default -1 means the last

  • step (int, default=1) – the incrementation if it is necessary to skip frames

  • pbc (bool, default=True) – True if periodic boundary conditions must be considered, False if not.

calculate(box=None)

Calculate the CN.

Parameters:

box (np.array, default=None) – the lenght of the box in each x, y, z direction, required when the trajectory is in an xyz file.

Returns:

a tuple with the average cn number and its standard deviation.

Return type:

tuple

to_dataframe()

Convert the results to a pandas.DataFrame.

A one-column DataFrame where for the central atoms the corresponding coordination number averaged over the frames in which it was calculated is given and for the interacting atoms (which was not calculated) a np.nan.

Returns:

df – DataFrame with the coordination number data in the column “cn”.

Return type:

pd.DataFrame

exma.cluster module

Implementations of clustering.

class exma.cluster.EffectiveNeighbors(frames, type_c, type_i, start=0, stop=-1, step=1)

Bases: MDObservable

Emipirical way to describe charge transfer and coordination in solids.

The empirical effective coordination model [2], used to calculate the effective neighbors, assumes that the interact atoms donate more of its electron to the closest central atoms. Then, fractions of the interact atom can be assigned to the various central neighbors atoms [3].

Parameters:
  • frames (list) – a list with all the frames of the molecular dynamics trajectory, where each one is an exma.core.AtomicSystem.

  • type_c (int or str) – type of central atoms

  • type_i (int or str) – type of interacting atoms

  • start (int, default=0) – the initial frame

  • stop (int, default=-1) – the last frame, by default -1 means the last

  • step (int, default=1) – the incrementation if it is necessary to skip frames

References

calculate(box=None)

Calculate the Effective Neighbors.

Parameters:

box (np.array, default=None) – the lenght of the box in each x, y, z direction, required when the trajectory is in an xyz file.

Returns:

effective (interact) neighbor of the central atoms in the same order that are in the positions vector

Return type:

np.array

class exma.cluster.DBSCAN(type_c, type_i, eps, min_samples=2)

Bases: object

DBSCAN clustering using PBC for the distance matrix calculations.

Parameters:
  • type_c (int or str) – type of central atoms

  • type_i (int or str) – type of interacting atoms

  • eps (float) – a cutoff radius at which an atom is no longer considered part of the cluster.

  • min_samples (int, default=2) – number of atoms required to form a cluster.

Notes

If the system is not under periodic boundary conditions, then everything can be calculated from sklearn.cluster.DBSCAN using metrics=”euclidean”.

of_this_frame(frame, **kwargs)

Obtain the labels of the DBSCAN clustering the actual frame.

Parameters:
  • frame (exma.core.AtomicSystem) – with the information of the atomic system including the box

  • **kwargs – additional keyword arguments that are passed and are documented in sklearn.cluster.DBSCAN

Returns:

id_cluster – as explained in sklearn.cluster.DBSCAN. It contains the id number of the cluster to which belongs the corresponding atom (the array is sorted). A value of -1 means that the atom is isolated.

Return type:

np.array

characterize()

Characterization in number of clusters and isolated.

Returns:

with the number of clusters and the number of isolated atoms.

Return type:

tuple

exma.cluster.sro(rdf_x, rdf_y, rcut, **kwargs)

Short range order parameter.

To characterize the short range ordering of amorphous structures, defined in this work [4], using the itegration of the radial distribution function for diatomic systems.

This parameter indicates complete randomness if it is equal to zero, preference for unlike neighbors if it is less than zero, and preference for similar neighbors (clustering) if is greater than zero.

Parameters:
  • rdf_x (np.array) – x of the radial distribution function

  • rdf_y (np.array) – y of the radial distribution function

  • rcut (float) – cutoff radius

  • **kwargs – Additional keyword arguments that are passed and are documented in scipy.integrate.simpson.

Returns:

amorphous short range order parameter

Return type:

float

References

Electrochemistry

exma.electrochemistry module

Implementation of functions of interest in electrochemistry.

exma.electrochemistry.fractional_volume_change(df, reference_atoms, reference_volume)

Fractional volume change (fvc) with respect to an element A.

The fvc points are calculated using a normalization relative to the number of atoms in the reference structure and its volume

\[fvc = {\frac{N_{ref}}{V_{ref}}} \left( {\frac{V_x}{N_x}} - {\frac{V_{ref}}{N_{ref}}} \right)\]

where \(N_{ref}\) and \(V_{ref}\) are the number of atoms of type A and the volume of the reference structure, \(N_x\) and \(V_x\) are the number of atoms of type A and the volume of the structure at the \(x\) concentration.

Parameters:
  • df (pd.DataFrame) – a pd.DataFrame with the values of x (concentrations) in the first column and then columns with the number of atoms of type A in each structure, the corresponding equilibrium values of the volume and, optionally, with its respective error.

  • reference_atoms (int) – the number of atoms in the reference structure.

  • reference_volume (float) – the volume, in the corresponding units, of the reference structue.

Returns:

The input pd.DataFrame with extra columns with the fractional volume change and the respective error if it was possible to calculate, fvc and err_fvc, respectively.

Return type:

pd.DataFrame

Raises:

KeyError – if the number of atoms of type A or the volume are not defined in the pd.DataFrame as “natoms_a” and “volume”, respectively.

Notes

The names of the columns in the df must be the following ones:

“x”: x values

“volume”: volume

“natoms_a”: number of atoms of type A

“err_volume”: the error of each “volume” point, optional.

exma.electrochemistry.formation_energy(df, reference_energy_a, reference_energy_b, fetype='x')

Ideal approximation to the formation energy (FE).

\[E_f(x) = E_x - (x \cdot E_b + E_a)\]

where \(E_x\) is the energy per atom of type A, \(x\) the concentration and \(E_a\) and \(E_b\) the cohesive energies of A and B bulk materials.

The formation energy relative to the end members can also be calculated

\[E_f(x) = \frac{E - n_a \cdot E_a - n_b \cdot E_b}{n_a + n_b}\]
Parameters:
  • df (pd.DataFrame) – a pd.DataFrame with the values of x (concentrations) in the first column and then columns with the number of atoms of types A and the equilibrium values of the potential energy and, optionally, with its respective error.

  • reference_energy_a (float) – the pure energy of element A in bulk

  • reference_energy_b (float) – the pure energy of element B in bulk

  • fetype (str, default="x") – “x” or “relative”, where the first one is the formation energy as a function of concentrations and the second one is relative to end members

Returns:

The input pd.DataFrame with the formation energy corresponding values, “fe”, and the respective error if it was possible to calculate, “err_fe”.

Return type:

pd.DataFrame

Notes

The names of the columns in the df must include:

“x” o “mol”: x or mol fraction values

“natoms_a”: number of atoms of type A

“natoms_b”: number of atoms of type B

“epot”: potential energy

“err_epot”: the error of each “epot” point, optional.

exma.electrochemistry.voltage(df, nums=50, **kwargs)

Approximation to the voltage curve.

The formation energies can be used as an approximation to the Gibbs formation energy, then the potential \(V\) is given by:

\[V(x) = -{\frac{dE_f(x)}{dx}}\]
Parameters:
  • df (pd.DataFrame) – a pd.DataFrame with the values of x (concentrations), the formation energy, “fe”, and, optionally, the respective error, “err_fe”.

  • nums (int, default=50) – number of points at which to evaluate the spline and its derivative

  • **kwargs – additional keyword arguments that are passed and are documented in scipy.interpolate.UnivariateSpline

Returns:

A pd.DataFrame with the value of the formation energy after the spline and the estimated value to the voltage in function of x.

Return type:

pd.DataFrame

exma.statistics module

An estimator of the error of a serie of data.

It is intended to facilitate the estimation of the error of thermodynamic quantities before using them to calculate electrochemical properties.

class exma.statistics.BlockAverage(x)

Bases: object

Estimating error method when data are correlated.

This method offers an easy and efficient way to estimate the error of correlated data by a renormalization groups, as described by H. Flyvbjerg and H. G. Petersen [1].

Parameters:

x (np.array) – where the time series is

References

calculate()

Calculate the estimation of the error.

Returns:

A pd.DataFrame with data_size, mean, var and varerr as columns that gives information about the data size changes, the mean value of each block, the corresponding variance and the error of that variance, respectively.

Return type:

pd.DataFrame

plot(ax=None, errorbar_kws=None)

Flyvbjerg & Petersen plot.

Parameters:
  • ax (matplotlib.pyplot.Axis, default=None) – current metplotlib axis

  • errorbar_kws (dict, default={"marker": "o", "ls": ""}) – additional keyword arguments that are passed and are documented in matplotlib.pyplot.errorbar_kws.

Returns:

the axis with the plot

Return type:

matplotlib.pyplot.Axis

IO

exma.io module

exma IO module for interacting with molecular dynamics files.

exma.io.xyz2lammpstrj(xyztraj, lammpstrj_name, cell_info, xyzftype='xyz')

Rewrite an xyz file to a lammpstrj file.

Parameters:
  • xyztraj (str) – the name of the file with the xyz trajectory.

  • lammpstrj_name (str) – the name of the file with the lammpstrj trajectory.

  • cell_info (dict) – with the box, the lenght of the box in each direction, another dictionary identified with the type key that has within it a correspondence between the elements present in xyz file with integer identification numbers, e.g. {“Sn”: 1, “O”: 2}

  • xyzftype (str, default="xyz") – the ftype of xyz file.

exma.io.xyz2inlmp(xyztraj, inlammps_name, cell_info, nframe=-1, xyzftype='xyz')

Write an xyz frame to an input data file of LAMMPS.

Parameters:
  • xyztraj (str) – the name of the file with the xyz trajectory.

  • inlammps_name (str) – the name of the file to write to.

  • cell_info (dict) – with the box, the lenght of the box in each direction, another dictionary identified with the type key that has within it a correspondence between the elements present in xyz file with integer identification numbers, e.g. {“Sn”: 1, “O”: 2}

  • nframe (int, default=-1) – number of the frame to write, by default is -1, that is, the last.

  • xyzftype (str, default="xyz") – the ftype of xyz file.

Raises:

IndexError – If the number of the frame to write is not in the trajectory file.

exma.io.lammpstrj2xyz(lammpstrjtraj, xyz_name, type_info, xyzftype='xyz')

Rewrite a lammpstrj file to an xyz file.

Parameters:
  • lammpstrjtraj (str) – the name of the file with the lammpstrj trajectory.

  • xyz_name (str) – the name of the file with the lammpstrj trajectory.

  • type_info (dict) – a correspondence between the elements id present in lammpstrj file with str element, e.g. {1: “Sn”, 2: “O”}

  • xyzftype (str, default="xyz") – the ftype of xyz file.

exma.io.lammpstrj2inlmp(lammpstrjtraj, inlammps_name, nframe=-1)

Write a lammpstrj frame to an input data file of LAMMPS.

Parameters:
  • lammpstrjtraj (str) – the name of the file with the lammpstrj trajectory.

  • inlammps_name (str) – the name of the file to write to.

  • nframe (int, default=-1) – number of the frame to write, by default is -1, that is, the last.

Raises:

IndexError – If the number of the frame to write is not in the trajectory file.

exma.io.reader module

Classes and functions to read MD trayectories.

exma.io.reader.read_xyz(filename, ftype='xyz')

Read xyz file.

Parameters:
  • filename (str) – name of the file where the trajectories in xyz format are

  • ftype (str, default="xyz") – the possible values are xyz, property, image and velocity. xyz if is the usual xyz file. property if in the last column there is a property. image if in the last three columns there are the image box of the corresponding atom. velocity if in the last three columns there are the velocities in each direction of the corresponding atoms.

Returns:

A list with an exma.core.AtomicSystem for each frame.

Return type:

list

exma.io.reader.read_lammpstrj(filename, headerint=['idx', 'types', 'ix', 'iy', 'iz'])

Read lammpstrj file.

Parameters:
  • filename (str) – name of the file where the trajectories of lammps are

  • headerint (list, default=["idx", "types", "ix", "iy", "iz"]) – the columns that have int data types, the others are considered floats.

Returns:

A list with an exma.core.AtomicSystem for each frame.

Return type:

list

exma.io.reader.read_log_lammps(logname='log.lammps')

Read log file of lammps.

Parameters:

logname (str, defalut="log.lammps".) – the name of the file where the thermodynamic info was logged.

Returns:

A pd.DataFrame with the columns corresponding to the thermodynamic info.

Return type:

pd.DataFrame

Notes

It only works if the first thermo parameter is Step.

class exma.io.reader.XYZ(filename, ftype='xyz')

Bases: TrajectoryReader

Class to read xyz files.

Parameters:
  • filename (str) – name of the file where the trajectories in xyz format are

  • ftype (str, default="xyz") – the possible values are xyz, property, image and velocity. xyz if is the usual xyz file. property if in the last column there is a property. image if in the last three columns there are the image box of the corresponding atom. velocity if in the last three columns there are the velocities in each direction of the corresponding atoms.

Raises:

ValueError – If xyz file type is not among the possible values

read_frame()

Read the actual frame of an .xyz file.

Returns:

frame – This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Raises:

EOFError – If there are no more frames to read

read_traj()

Read all the trajectory of the file.

class exma.io.reader.LAMMPS(filename, headerint=['idx', 'types', 'ix', 'iy', 'iz'])

Bases: TrajectoryReader

Class to read lammpstrj files.

Parameters:
  • filename (str) – name of the file where the trajectories of lammps are

  • headerint (list, default=["idx", "types", "ix", "iy", "iz"]) – the columns that have int data types, the others are considered floats.

read_frame()

Read the actual frame of an .lammpstrj file.

Returns:

frame – This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Raises:

EOFError – If there are no more frames to read

read_traj()

Read all the trajectory of the file.

exma.io.writer module

Classes and functions to write MD trayectories.

exma.io.writer.write_xyz(frames, filename, ftype='xyz')

Write an xyz file.

Parameters:
  • frames (list) – A list with an exma.core.AtomicSystem for each frame of the trajectory.

  • filename (str) – name of the file where the trajectories in xyz format are

  • ftype (str, default="xyz") – the possible values are xyz, property and image. xyz if is the usual xyz file. property if in the last column there is a property. image if in the last three columns there are the image box of the corresponding atom.

exma.io.writer.write_lammpstrj(frames, filename)

Write a lammpstrj file.

Parameters:
  • frames (list) – A list with an exma.core.AtomicSystem for each frame of the trajectory.

  • filename (str) – name of the file where the trajectories in xyz format are

exma.io.writer.write_in_lammps(frame, file_in)

Write a frame as an input file for LAMMPS.

Parameters:
  • frame (exma.core.AtomicSystem) – This have all the information of the configurations of the system.

  • file_in (str) – name of the file where you want to write the input info

class exma.io.writer.XYZ(filename, ftype='xyz')

Bases: TrajectoryWriter

Class to write xyz files.

Parameters:
  • filename (str) – name of the file where the trajectories in xyz format are going to be written

  • ftype (str, default="xyz") – the possible values are xyz, property and image. xyz if is the usual xyz file. property if in the last column there is a property. image if in the last three columns there are the image box of the corresponding atom.

Raises:

ValueError – If xyz file type is not among the possible values

write_frame(frame)

Write the actual frame in an .xyz file.

Parameters:

frame (exma.core.AtomicSystem) – This have all the information of the configurations of the system.

write_traj(frames)

Write all frames of the trajectory to a file.

class exma.io.writer.LAMMPS(filename, ftype='custom')

Bases: TrajectoryWriter

Class to write lammpstrj files.

Parameters:

filename (str) – name of the file where the trajectories of lammps are going to be written

write_frame(frame)

Write the actual frame in a .lammpstrj file.

Parameters:

frame (exma.core.AtomicSystem) – This have all the information of the configurations of the system.

write_traj(frames)

Write all frames of the trajectory to a file.

exma.io.positions module

Includes class and functions to define atom positions.

It is primarily developed to generate initial structures returned in the form of a exma.core.AtomicSystem for writing to output files with the writer classes/function that serve as initial conditions for simulations.

class exma.io.positions.Positions(natoms, box_size)

Bases: object

Define the positions of the atoms in an orthogonal lattice.

Parameters:
  • natoms (int) – number of atoms

  • box_size (float) – box size in each direction (cubic)

Notes

Note that the density is defined by the input parameters as follow:

\[{\rho} = {\frac{N}{L^3}}\]

where N is the number of atoms and L the box lenght in each direction.

sc()

Simple-cubic crystal.

This cell is characterized by having an atom in each of its vertices.

Returns:

This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Raises:

ValueError – If the number of atoms does not correspond with the number of sites that a sc crystal structure has.

bcc()

Body-centered cubic crystal.

This cell is characterized by having one atom in each of its vertices and an additional atom in the center of the cube.

Returns:

This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Raises:

ValueError – If the number of atoms does not correspond with the number of sites that a bcc crystal structure has.

fcc()

Face-centered cubic crystal.

This cell is characterized by having one atom in each of its vertices and an additional atom in each of its faces.

Returns:

This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Raises:

ValueError – If the number of atoms does not correspond with the number of sites that a fcc crystal structure has.

dc()

Diamond cubic crystal.

The typical structure of a diamond, defined by eight sites.

Returns:

This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Raises:

ValueError – If the number of atoms does not correspond with the number of sites that a dc crystal structure has.

exma.io.positions.spherical_nanoparticle(frame, rcut)

Cut a defined structure to give a spherical nanoparticle.

Parameters:
  • frame (exma.core.AtomicSystem) – This have all the information of the configurations of the system.

  • rcut (float) – the radius of the nanoparticle.

Returns:

This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Notes

If rcut is greater than half the cell length, the cell will be replicated to give a nanoparticle of the desired radius.

exma.io.positions.replicate(frame, nrf)

Replicate a crystalline system in each direction.

Parameters:
  • frame (exma.core.AtomicSystem) – This have all the information of the configurations of the system.

  • nrf (list) – three integers that must be greater than or equal to 1 and indicates the replication factor in each x, y, z direction, respectively. Value equal to 1 means that only the current cell in that direction is considered.

Returns:

This have all the information of the configurations of the system.

Return type:

exma.core.AtomicSystem

Distances with periodic boundary conditions (PBC distances)

exma.distances module

Distances with Periodic Boundary Conditions.

exma.distances.pbc_distances(frame_c, frame_i, type_c='all', type_i='all')

Periodic boundary conditions distances.

A function to compute the distances between a central and an interact group of atoms with the minimum image convention, in which each individual particle inteacts with the closest image of the copies of the system.

Parameters:
  • frame_c (exma.core.AtomicSystem) – which have the atomic configurations of the central atoms and must include box not None.

  • frame_i (exma.core.AtomicSystem) – which have the atomic configurations of the interact atoms and must include box not None.

  • type_c (int or str, default="all") – type of central atoms, by default it computes the distances for all the atoms

  • type_i (int or str, default="all") – type of interacting atoms, by default it computes the distances for all the atoms

Returns:

array with the distance matrix where the rows are the central atoms and the columns the interacting ones.

Return type:

np.array

Dev Core modules

exma.core module

Core classes of exma.

class exma.core.AtomicSystem(natoms=None, box=None, types=None, idx=None, q=None, x=None, y=None, z=None, ix=None, iy=None, iz=None, vx=None, vy=None, vz=None)

Bases: object

Define the configurations of the atomic system.

Parameters:
  • natoms (int, default=None) – the number of atoms in the atomic system

  • box (np.array, default=None) – the box lenght in each direction

  • types (np.array, default=None) – the types of the atoms

  • idx (np.array, default=None) – the index of the atoms

  • q (np.array, default=None) – a property of each atom in the atomic system

  • x (np.array, default=None) – the positions of the atoms in the x direction

  • y (np.array, default=None) – the positions of the atoms in the y direction

  • z (np.array, default=None) – the positions of the atoms in the z direction

  • ix (np.array, default=None) – the corresponding image of the positions of the atoms in the x direction

  • iy (np.array, default=None) – the corresponding image of the positions of the atoms in the y direction

  • iz (np.array, default=None) – the corresponding image of the positions of the atoms in the z direction

  • vx (np.array, default=None) – the velocities of the atoms in the x direction

  • vy (np.array, default=None) – the velocities of the atoms in the y direction

  • vz (np.array, default=None) – the velocities of the atoms in the z direction

_mask_type(atom_type)

Get a masked array by an specific type of atom.

_natoms_type(mask_type)

Count the number of atoms of an specific type.

_sorted()

Tells if the array x is sorted (-> True) or not (-> False).

Note that for xyz files self.idx is None and the frame is sorted by definition.

_sort(dontsort=('natoms', 'box'))

Sort the Atomic System from the sortening of the atoms id.

_unwrap(m=None)

Unwrap the Atomic System m masked outside the box.

_wrap(m=None)

Wrap the Atomic System m masked inside the box.

class exma.core.MDObservable(frames, start=0, stop=-1, step=1)

Bases: object

Class to define the structure of the molecular dynamics observable.

Parameters:
  • frames (list) – a list with all the frames of the molecular dynamics trajectory, where each one is an exma.core.AtomicSystem.

  • start (int, default=0) – the initial frame

  • stop (int, default=-1) – the last frame, by default -1 means the last

  • step (int, default=1) – the incrementation if it is necessary to skip frames

_local_configure(frame)

Specific configuration of each observable.

_accumulate(frame)

Accumulate the data of the frame.

_end(frame)

Finish the calculation and normilize the data.

_calculate(box=None)

Observable main loop, leave everything ready to do self._end().

Parameters:

box (np.array, default=None) – the lenght of the box in each x, y, z direction, required when the trajectory comes from an xyz file.

calculate()

Calculate the observable.

to_dataframe()

Convert the results to pandas.DataFrame.

plot()

Make a plot of the observable.

class exma.core.TrajectoryReader(filename, ftype)

Bases: object

Class to read trajectory files.

Parameters:
  • filename (str) – name of the file where the trajectories in xyz format are

  • ftype (str) – different type of files depending on the child class.

read_frame()

Read the actual frame of the file.

read_traj()

Read all the trajectory of the file.

class exma.core.TrajectoryWriter(filename, ftype)

Bases: object

Class to write trajectory files.

Parameters:
  • filename (str) – name of the file where the trajectories in xyz format are going to be written

  • ftype (str) – different type of files depending on the child class.

write_frame(frame)

Write the actual frame on the file.

write_traj(frames)

Write all frames of the trajectory to a file.