cmmdft package
Submodules
cmmdft.calculator module
cmmdft.eos module
cmmdft.free_energy module
cmmdft.functionals module
cmmdft.grid module
Tools to perform classical DFT simulations
- class cmmdft.grid.Cell(rvecs)[source]
Bases:
objectSimulation cell with periodicity information.
Represents the simulation box geometry defined by lattice vectors, and provides coordinate transformation utilities. Supports orthogonal and non-orthogonal (triclinic) cells.
- rvecs
- Lattice vectors as rows: [[a_x, a_y, a_z],
[b_x, b_y, b_z], [c_x, c_y, c_z]]
- Type:
ndarray
- inv_rvecs
Inverse of the lattice vector matrix
- Type:
ndarray
- __init__(rvecs)[source]
Initialize a simulation cell.
- Parameters:
rvecs (array_like) – 3x3 matrix of lattice vectors as rows, shape (3, 3)
- cart_to_frac(cart_coords)[source]
Convert Cartesian coordinates to fractional (reduced) coordinates.
- Parameters:
cart_coords (array_like) – Cartesian coordinates with shape (…, 3)
- Returns:
Fractional coordinates with same shape as input, where each coordinate is expressed as a linear combination of lattice vectors
- Return type:
ndarray
Examples
>>> cell = Cell(np.eye(3) * 5.0) >>> frac = cell.cart_to_frac([2.5, 2.5, 2.5]) >>> np.allclose(frac, [0.5, 0.5, 0.5]) True
- copy()[source]
Create a deep copy of the cell.
- Returns:
Independent copy of this cell object
- Return type:
- frac_to_cart(frac_coords)[source]
Convert fractional (reduced) coordinates to Cartesian coordinates.
- Parameters:
frac_coords (array_like) – Fractional coordinates with shape (…, 3), where last dimension contains fractional coordinates in basis of lattice vectors
- Returns:
Cartesian coordinates with same shape as input
- Return type:
ndarray
Examples
>>> cell = Cell(np.eye(3) * 5.0) >>> cart = cell.frac_to_cart([0.5, 0.5, 0.5]) >>> np.allclose(cart, [2.5, 2.5, 2.5]) True
- mic(delta_cart)[source]
Apply the minimum image convention (MIC) to displacement vectors.
Maps displacement vectors to their nearest periodic images by converting to fractional coordinates, wrapping to [-0.5, 0.5), and converting back to Cartesian.
- Parameters:
delta_cart (array_like) – Cartesian displacement vectors with shape (…, 3), where last dimension contains the 3D displacement
- Returns:
Shortest displacement vectors under periodic boundary conditions, same shape as input
- Return type:
ndarray
- Raises:
ValueError – If last dimension is not size 3
Notes
Essential for simulating systems with periodic boundary conditions. Ensures distances are calculated using periodic neighbors.
Examples
>>> cell = Cell(np.eye(3) * 10.0) >>> delta = cell.mic([8.0, 0.0, 0.0]) # > a/2 >>> np.allclose(np.linalg.norm(delta), 2.0) # Should wrap to -2 True
- class cmmdft.grid.Grid(cell, npoints=None, spacing=0.472431533480313)[source]
Bases:
objectDiscrete spatial grid for classical DFT calculations.
Discretizes the simulation domain into real-space and reciprocal-space grids for efficient computation of functionals and Fourier transforms. Provides integration and FFT operations on fields defined on the grid.
Note: Be aware that FFT efficiency depends heavily on the number of points, preferably choose powers of 2.
- npoints
Number of grid points in each direction [nx, ny, nz]
- Type:
ndarray
- spacings
Grid spacing in each direction (Angstrom)
- Type:
ndarray
- points
Real-space grid point coordinates with shape (nx, ny, nz, 4), where last dimension contains [x, y, z, r]
- Type:
ndarray
- kpoints
Reciprocal-space grid point coordinates with shape (nx, ny, nz, 4), where last dimension contains [kx, ky, kz, \(|k|\)]
- Type:
ndarray
- sigma_lanczos
Lanczos kernel for FFT to reduce Gibbs phenomenon
- Type:
ndarray
- __init__(cell, npoints=None, spacing=0.472431533480313)[source]
Initialize a discrete spatial grid.
- Parameters:
cell (Cell) – Cell object defining the simulation domain
npoints (int or list, optional) – Grid dimensions [nx, ny, nz]. If a single integer is given, equal dimensions in each direction are assumed. If None, grid points are determined from cell dimensions and spacing. Default is None
spacing (float, optional) – Spacing between grid points in Angstrom. Only used to determine npoints if npoints is None. Default is 0.25 Angstrom
- copy()[source]
Create a deep copy of the grid.
- Returns:
Independent copy of this grid object
- Return type:
- fft(rdata)[source]
Fast Fourier transform a real-space field with phase correction.
Applies FFT with phase factor correction. Legacy method for single-component grids with shape (nx, ny, nz). For fields with additional dimensions, use fftn() instead.
- Parameters:
rdata (ndarray) – Real-space field with shape (nx, ny, nz)
- Returns:
Reciprocal-space field (complex)
- Return type:
ndarray
- fftn(rdata)[source]
Fourier transform along the 3 spatial axes with phase correction.
Applies FFT with phase factor correction and supports fields with arbitrary leading/trailing dimensions beyond the spatial block.
- Parameters:
rdata (ndarray) – Real-space field with spatial dimensions (nx, ny, nz) anywhere in the shape, e.g.: (N,N,N), (N,N,N,M), (M,N,N,N), (M1,N,N,N,M2)
- Returns:
Reciprocal-space field (complex) with same shape as input
- Return type:
ndarray
- Raises:
ValueError – If spatial block (nx, ny, nz) is not found in input shape
- ifft(fdata)[source]
Inverse Fourier transform a reciprocal-space field with phase correction.
Applies inverse FFT with phase factor correction. Legacy method for single-component grids with shape (nx, ny, nz). For fields with additional dimensions, use ifftn() instead.
- Parameters:
fdata (ndarray) – Reciprocal-space field (complex) with shape (nx, ny, nz)
- Returns:
Real-space field (real values)
- Return type:
ndarray
- ifftn(fdata)[source]
Inverse Fourier transform along the 3 spatial axes with phase correction.
Applies inverse FFT with phase factor correction and supports fields with arbitrary leading/trailing dimensions beyond the spatial block.
- Parameters:
fdata (ndarray) – Reciprocal-space field (complex) with spatial dimensions (nx, ny, nz) anywhere in the shape, e.g.: (N,N,N), (N,N,N,M), (M,N,N,N), etc.
- Returns:
Real-space field (real values) with same shape as input
- Return type:
ndarray
- Raises:
ValueError – If spatial block (nx, ny, nz) is not found in input shape
- integrate_n(data)[source]
Integrate a field over the entire grid domain.
Integrates along the 3 spatial axes (matching self.npoints). Supports fields with arbitrary leading/trailing dimensions.
- Parameters:
data (ndarray) – Field values with spatial dimensions (nx, ny, nz) anywhere in the shape. Supports arbitrary leading/trailing dimensions
- Returns:
Integral of the field over the domain
- Return type:
- Raises:
ValueError – If spatial block (nx, ny, nz) is not found in input shape
cmmdft.guest_dict module
cmmdft.integrate_flexibility module
cmmdft.log module
cmmdft.plotter module
cmmdft.program module
cmmdft.solver module
cmmdft.system module
cmmdft.tools module
cmmdft.units_constants module
cmmdft.external_potential package
The external potential utilities are part of the main package API and are included here alongside the rest of the CmmDFT modules.
cmmdft.external_potential.extpot_calculator module
cmmdft.external_potential.interpolator module
cmmdft.external_potential.parameters module
Object-oriented representation of parameter files
- class cmmdft.external_potential.parameters.Complain(filename='__nofile__')[source]
Bases:
objectClass for complain method of ParameterFile and ParameterSection
- class cmmdft.external_potential.parameters.ParameterDefinition(suffix, lines=None, complain=None)[source]
Bases:
objectObject that represents a set of data lines from a parameter file
- class cmmdft.external_potential.parameters.ParameterSection(prefix, definitions=None, complain=None)[source]
Bases:
objectObject that represents one section in a force field parameter file
- class cmmdft.external_potential.parameters.Parameters(sections=None)[source]
Bases:
objectObject that represents a force field parameter file
The parameter file is first parsed by this object into a convenient data structure with dictionaries. The actual force field is then generated based on these dictionaries.
The parameter file has a purely line-based syntax. The order of the lines has no meaning. Comments begin with a hash sign (#) and continue till the end of a line. If the line is empty after stripping the comments, it is ignored. Every non-empty line should have the following format:
PREFIX:SUFFIX DATA
The prefix is used for sections, the suffix for definitions and the remainder of the line contains arguments for the definition. Definitions may be repeated with different or the same arguments.