API Reference¶
This section contains the auto-generated API documentation for the toolbox package, created from the numpy-style docstrings in the source code.
Calculator Module¶
Bash Calculator¶
toolbox.calculator.bash
¶
Bash calculator for running external commands.
This module provides a calculator interface for running bash commands and external programs with proper error handling and logging.
BashCalculator
¶
A calculator for running bash commands in a specified working directory.
This class provides functionality to execute shell commands with proper directory management and logging.
Source code in toolbox/calculator/bash.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
__init__(work_dir)
¶
Initialize the BashCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
str
|
The working directory where commands will be executed |
required |
Source code in toolbox/calculator/bash.py
19 20 21 22 23 24 25 26 27 | |
run(command=None, stdin=None, stdout='job.stdout', stderr='job.stderr', mpi_command='mpiexec.hydra', ignore_finished_tag=False)
¶
Execute a command in the working directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Command to execute, by default None |
None
|
stdin
|
str
|
Standard input file, by default None |
None
|
stdout
|
str
|
Standard output file, by default "job.stdout" |
'job.stdout'
|
stderr
|
str
|
Standard error file, by default "job.stderr" |
'job.stderr'
|
mpi_command
|
str
|
MPI command to use, by default "mpiexec.hydra" |
'mpiexec.hydra'
|
ignore_finished_tag
|
bool
|
Whether to ignore existing finished tag, by default False |
False
|
Source code in toolbox/calculator/bash.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
Coulomb Calculator¶
toolbox.calculator.coulomb
¶
Coulomb interaction calculators for molecular simulations.
This module provides calculators for: - Coulomb cutoff interactions - Ewald summation methods - Particle Mesh Ewald (PME) calculations - D3 dispersion corrections
These calculators are used for computing electrostatic interactions in molecular dynamics simulations.
CoulCutCalculator
¶
Calculator for Coulomb interactions with cutoff.
This calculator computes Coulomb interactions between atoms using a simple cutoff scheme.
Source code in toolbox/calculator/coulomb.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__init__(cutoff=5.0)
¶
Initialize CoulCutCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Cutoff distance in Angstroms, by default 5.0 |
5.0
|
Source code in toolbox/calculator/coulomb.py
114 115 116 117 118 119 120 121 122 | |
calculate(atoms)
¶
Calculate Coulomb energy and forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object with positions and charges |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (energy, forces) where energy is in eV and forces is an array in eV/A |
Source code in toolbox/calculator/coulomb.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
CoulLongCalculator
¶
Calculator for long-range Coulomb interactions with Ewald summation.
This calculator computes Coulomb interactions using Ewald summation with complementary error function screening.
Source code in toolbox/calculator/coulomb.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
__init__(gewald, cutoff=5.0)
¶
Initialize CoulLongCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gewald
|
float
|
Ewald screening parameter |
required |
cutoff
|
float
|
Real-space cutoff distance in Angstroms, by default 5.0 |
5.0
|
Source code in toolbox/calculator/coulomb.py
166 167 168 169 170 171 172 173 174 175 176 177 | |
calculate(atoms)
¶
Calculate Coulomb energy and forces with Ewald summation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object with positions and charges |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (energy, forces) where energy is in eV and forces is an array in eV/A |
Source code in toolbox/calculator/coulomb.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
DMFFPMECalculator
¶
Calculator for Coulomb interactions using Particle Mesh Ewald (PME).
This calculator uses the DMFF library to compute Coulomb interactions with PME for efficient long-range electrostatics.
Source code in toolbox/calculator/coulomb.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
__init__(cutoff=6.0)
¶
Initialize DMFFPMECalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Real-space cutoff distance in Angstroms, by default 6.0 |
6.0
|
Source code in toolbox/calculator/coulomb.py
226 227 228 229 230 231 232 233 234 | |
calculate(atoms, ethresh=1e-06)
¶
Calculate Coulomb energy using PME.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object with positions and charges |
required |
ethresh
|
float
|
Ewald threshold, by default 1e-6 |
1e-06
|
Returns:
| Type | Description |
|---|---|
float
|
Coulomb energy in eV/particle |
Source code in toolbox/calculator/coulomb.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
setup_ewald(box, ethresh)
¶
Set up Ewald parameters for PME calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box
|
array_like
|
Simulation box vectors |
required |
ethresh
|
float
|
Ewald threshold |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (kappa, K) where kappa is the screening parameter and K is the grid dimensions |
Source code in toolbox/calculator/coulomb.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
calculate_pairs(atoms, rcut)
¶
Calculate atom pairs within cutoff distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object |
required |
rcut
|
float
|
Cutoff distance in Angstroms |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of atom pairs within cutoff, each as [i, j, 0] |
Source code in toolbox/calculator/coulomb.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
coul(qi, qj, rij)
¶
Calculate Coulomb energy between two point charges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qi
|
float
|
First charge in elementary charge units (e) |
required |
qj
|
float
|
Second charge in elementary charge units (e) |
required |
rij
|
float
|
Distance between charges in Angstroms (A) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Coulomb energy in electron volts (eV) |
Source code in toolbox/calculator/coulomb.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
real_coul(qi, qj, xi, xj, gewald, force=False)
¶
Calculate real-space Coulomb energy with Ewald summation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qi
|
float
|
First charge in elementary charge units (e) |
required |
qj
|
float
|
Second charge in elementary charge units (e) |
required |
xi
|
array_like
|
Position of first charge |
required |
xj
|
array_like
|
Position of second charge |
required |
gewald
|
float
|
Ewald screening parameter |
required |
force
|
bool
|
Whether to calculate forces, by default False |
False
|
Returns:
| Type | Description |
|---|---|
float or tuple
|
If force=False, returns Coulomb energy in eV If force=True, returns tuple of (energy, force) |
Source code in toolbox/calculator/coulomb.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
CP2K Calculator¶
toolbox.calculator.cp2k
¶
CP2K quantum chemistry calculator interface.
This module provides a calculator interface for running CP2K quantum chemistry calculations with proper error handling and output checking.
Cp2kCalculator
¶
Bases: BashCalculator
A calculator for running CP2K quantum chemistry calculations.
This class extends BashCalculator to provide specific functionality for CP2K calculations, including error handling and output checking.
Source code in toolbox/calculator/cp2k.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__init__(work_dir)
¶
Initialize the Cp2kCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
str
|
The working directory where CP2K calculations will be executed |
required |
Source code in toolbox/calculator/cp2k.py
23 24 25 26 27 28 29 30 31 | |
run(command='cp2k.popt', stdin='input.inp', stdout='output.out', stderr='cp2k.stderr', mpi_command='mpiexec.hydra', ignore_finished_tag=False, ignore_err=True)
¶
Run a CP2K calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
CP2K executable command, by default "cp2k.popt" |
'cp2k.popt'
|
stdin
|
str
|
Input file name, by default "input.inp" |
'input.inp'
|
stdout
|
str
|
Standard output file name, by default "output.out" |
'output.out'
|
stderr
|
str
|
Standard error file name, by default "cp2k.stderr" |
'cp2k.stderr'
|
mpi_command
|
str
|
MPI command to use, by default "mpiexec.hydra" |
'mpiexec.hydra'
|
ignore_finished_tag
|
bool
|
Whether to ignore existing finished tag, by default False |
False
|
ignore_err
|
bool
|
Whether to ignore calculation errors, by default True |
True
|
Source code in toolbox/calculator/cp2k.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
D3 Calculator¶
toolbox.calculator.d3
¶
D3 dispersion correction calculator.
This module provides a calculator for Grimme's D3 dispersion corrections using the tad_dftd3 library.
D3Calculator
¶
Calculator for D3 dispersion corrections.
This calculator computes Grimme's D3 dispersion corrections using the tad_dftd3 library.
Source code in toolbox/calculator/d3.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__init__(params=None)
¶
Initialize D3Calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Optional[Dict]
|
D3 parameters dictionary, by default None. If None, uses r²SCAN-D3(BJ) parameters. |
None
|
Source code in toolbox/calculator/d3.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
run(atoms)
¶
Calculate D3 dispersion energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object with atomic numbers and positions |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
D3 dispersion energy |
Source code in toolbox/calculator/d3.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
Deep Potential Calculator¶
toolbox.calculator.dp
¶
Deep Potential dispatcher module.
This module provides classes for dispatching Deep Potential calculations to HPC systems using dpdispatcher.
CP2KDPDispatcher
¶
Bases: DPDispatcher
Dispatcher for running CP2K calculations with Deep Potential.
This class extends DPDispatcher to provide specific functionality for CP2K calculations with version-specific configurations.
Source code in toolbox/calculator/dp.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
__init__(work_dir='.', v9=False)
¶
Initialize CP2KDPDispatcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
str
|
Working directory for calculations, by default "." |
'.'
|
v9
|
bool
|
Whether to use CP2K v9 configuration, by default False |
False
|
Source code in toolbox/calculator/dp.py
159 160 161 162 163 164 165 166 167 168 169 170 | |
run(dnames, machine_setup=None, resources_setup=None, task_setup=None)
¶
Run CP2K calculations on specified directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dnames
|
list
|
List of directory names to run calculations in |
required |
machine_setup
|
dict
|
Machine configuration overrides, by default {} |
None
|
resources_setup
|
dict
|
Resources configuration overrides, by default {} |
None
|
task_setup
|
dict
|
Task configuration overrides, by default {} |
None
|
Source code in toolbox/calculator/dp.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
DPDispatcher
¶
Dispatcher for running Deep Potential calculations.
This class provides functionality to dispatch Deep Potential calculations to HPC systems using dpdispatcher.
Source code in toolbox/calculator/dp.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
__init__(work_dir='.')
¶
Initialize DPDispatcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
str
|
Working directory for calculations, by default "." |
'.'
|
Source code in toolbox/calculator/dp.py
18 19 20 21 22 23 24 25 26 | |
run(dnames, machine_setup=None, resources_setup=None, task_setup=None)
¶
Run calculations on specified directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dnames
|
list
|
List of directory names to run calculations in |
required |
machine_setup
|
dict
|
Machine configuration overrides, by default {} |
None
|
resources_setup
|
dict
|
Resources configuration overrides, by default {} |
None
|
task_setup
|
dict
|
Task configuration overrides, by default {} |
None
|
Source code in toolbox/calculator/dp.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
Electric Potential Calculator¶
toolbox.calculator.elecpot
¶
Electrostatic potential calculator module.
This module provides classes for calculating electrostatic potential from charge density using various boundary conditions.
Reference: - https://altafang.com/2020/10/13/calculating-1d-electrostatic-potential-profile-from-md-simulations/ - Code from Justina Moss (Leiden University, Email: j.h.moss@lic.leidenuniv.nl) - https://github.com/SINGROUP/Potential_solver.
ElecPotentialCalculator
¶
Calculator for 1D electrostatic potential from charge density.
This calculator computes electrostatic potential from charge density using various boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge
|
array_like
|
Charge density in e/ų |
required |
grid
|
array_like
|
Grid points in Ã… |
required |
Returns:
| Type | Description |
|---|---|
Electrostatic potential in eV
|
(different from Hartree potential with a negative sign!) |
Source code in toolbox/calculator/elecpot.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
__init__(charge, grid)
¶
Initialize ElecPotentialCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge
|
array_like
|
Charge density in e/ų |
required |
grid
|
array_like
|
Grid points in Ã… |
required |
Source code in toolbox/calculator/elecpot.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
calculate(bc='periodic', **kwargs)
¶
Calculate electrostatic potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bc
|
str
|
Boundary condition, by default "periodic" Options: "periodic", "open", "dirichlet", "neumann", "dip_cor" |
'periodic'
|
**kwargs
|
Additional keyword arguments for specific boundary conditions |
{}
|
Returns:
| Type | Description |
|---|---|
array_like
|
Electrostatic potential in V |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If boundary condition is not supported |
Source code in toolbox/calculator/elecpot.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
solve_fft_poisson(l_box)
¶
Solve Poisson equation using FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l_box
|
float
|
Box length in Ã… |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
Electrostatic potential |
Source code in toolbox/calculator/elecpot.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
GaussianElecPotentialCalculator
¶
Calculator for electrostatic potential from Gaussian charge distributions.
This calculator computes electrostatic potential from atoms represented as Gaussian charge distributions.
Source code in toolbox/calculator/elecpot.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
__init__(grids, l_box, cross_area, spread_dict=None, charge_dict=None)
¶
Initialize GaussianElecPotentialCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grids
|
ndarray
|
Grid points in Ã… |
required |
l_box
|
float
|
Box length in Ã… |
required |
cross_area
|
float
|
Cross-sectional area in Ų |
required |
spread_dict
|
Optional[Dict[str, float]]
|
Dictionary of Gaussian spreads for each element, by default None |
None
|
charge_dict
|
Optional[Dict[str, float]]
|
Dictionary of charges for each element, by default None |
None
|
Source code in toolbox/calculator/elecpot.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
calc_rho(mu, spread, charge)
¶
Calculate charge density from Gaussian distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
ndarray
|
Centers of Gaussian distributions |
required |
spread
|
ndarray
|
Spreads of Gaussian distributions |
required |
charge
|
ndarray
|
Charges of Gaussian distributions |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Charge density on the grid |
Source code in toolbox/calculator/elecpot.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
run(mu=None, spread=None, charge=None, atoms=None)
¶
Calculate electrostatic potential from Gaussian charge distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Optional[ndarray]
|
Centers of Gaussian distributions, by default None |
None
|
spread
|
Optional[ndarray]
|
Spreads of Gaussian distributions, by default None |
None
|
charge
|
Optional[ndarray]
|
Charges of Gaussian distributions, by default None |
None
|
atoms
|
Optional[Atoms]
|
ASE Atoms object, by default None |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Electrostatic potential |
Source code in toolbox/calculator/elecpot.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
WannierHartreePotentialCalculator
¶
Bases: GaussianElecPotentialCalculator
Calculator for Hartree potential from Wannier functions.
This calculator extends GaussianElecPotentialCalculator to compute Hartree potential from Wannier functions.
Source code in toolbox/calculator/elecpot.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
__init__(grids, l_box, cross_area, spread_dict=None, charge_dict=None)
¶
Initialize WannierHartreePotentialCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grids
|
ndarray
|
Grid points in Ã… |
required |
l_box
|
float
|
Box length in Ã… |
required |
cross_area
|
float
|
Cross-sectional area in Ų |
required |
spread_dict
|
Optional[Dict[str, float]]
|
Dictionary of Gaussian spreads for each element, by default None |
None
|
charge_dict
|
Optional[Dict[str, float]]
|
Dictionary of charges for each element, by default None |
None
|
Source code in toolbox/calculator/elecpot.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
run(mu=None, spread=None, charge=None, atoms=None, dname=None, fname_coord='coord.xyz', fname_wannier='wannier.xyz')
¶
Calculate Hartree potential from Wannier functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Optional[ndarray]
|
Centers of Gaussian distributions, by default None |
None
|
spread
|
Optional[ndarray]
|
Spreads of Gaussian distributions, by default None |
None
|
charge
|
Optional[ndarray]
|
Charges of Gaussian distributions, by default None |
None
|
atoms
|
Optional[Atoms]
|
ASE Atoms object, by default None |
None
|
dname
|
Optional[str]
|
Directory name containing coordinate files, by default None |
None
|
fname_coord
|
Optional[str]
|
Coordinate file name, by default "coord.xyz" |
'coord.xyz'
|
fname_wannier
|
Optional[str]
|
Wannier coordinate file name, by default "wannier.xyz" |
'wannier.xyz'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Negative of the electrostatic potential (Hartree potential) |
Source code in toolbox/calculator/elecpot.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
LAMMPS Calculator¶
toolbox.calculator.lammps
¶
LAMMPS calculator module.
This module provides a calculator for running LAMMPS molecular dynamics simulations, extending the BashCalculator class.
LammpsCalculator
¶
Bases: BashCalculator
A calculator for running LAMMPS molecular dynamics simulations.
This class extends BashCalculator to provide specific functionality for LAMMPS calculations, including completion checking.
Source code in toolbox/calculator/lammps.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
__init__(work_dir)
¶
Initialize LammpsCalculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
str
|
The working directory where LAMMPS calculations will be executed |
required |
Source code in toolbox/calculator/lammps.py
22 23 24 25 26 27 28 29 30 | |
run(command='lmp', stdin='input.lmp', stdout='lammps.stdout', stderr='lammps.stderr', mpi_command='mpiexec.hydra', ignore_finished_tag=False, modifier=None)
¶
Run a LAMMPS calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
LAMMPS executable command, by default "lmp" |
'lmp'
|
stdin
|
str
|
Input file name, by default "input.lmp" |
'input.lmp'
|
stdout
|
str
|
Standard output file name, by default "lammps.stdout" |
'lammps.stdout'
|
stderr
|
str
|
Standard error file name, by default "lammps.stderr" |
'lammps.stderr'
|
mpi_command
|
str
|
MPI command to use, by default "mpiexec.hydra" |
'mpiexec.hydra'
|
ignore_finished_tag
|
bool
|
Whether to ignore existing finished tag, by default False |
False
|
modifier
|
str
|
Additional command modifiers, by default None |
None
|
Notes
For more information on LAMMPS run options, see: https://docs.lammps.org/Run_options.html
Source code in toolbox/calculator/lammps.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
I/O Module¶
ASE Logger¶
toolbox.io.ase_logger
¶
ASE MD Logger module.
This module provides an extended MDLogger class that can write trajectory files during molecular dynamics simulations.
MDLogger
¶
Bases: MDLogger
Extended MD Logger for ASE molecular dynamics.
This class extends ASE's MDLogger to provide additional functionality for writing trajectory files during MD simulations.
Source code in toolbox/io/ase_logger.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
__call__()
¶
Write trajectory data to file.
This method is called during MD simulation to write the current atomic configuration to the specified file.
Source code in toolbox/io/ase_logger.py
36 37 38 39 40 41 42 43 | |
BPNN I/O¶
toolbox.io.bpnn
¶
BPNN data reader module.
This module provides functionality to read BPNN (Behler-Parrinello Neural Network) data files for machine learning potentials.
read_data(fname='input.data')
¶
Read BPNN data file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to BPNN data file, by default "input.data" |
'input.data'
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (box, coord, charge, symbol, energy, force) where: - box: array of box parameters with shape (n_frames, 9) - coord: array of coordinates with shape (n_frames, n_atoms*3) - charge: array of charges with shape (n_frames, n_atoms) - symbol: list of element symbols for each frame - energy: array of energies with shape (n_frames,) - force: array of forces with shape (n_frames, n_atoms*3) |
Source code in toolbox/io/bpnn.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
System Builder¶
toolbox.io.build
¶
Molecular system building module.
This module provides classes and functions for building molecular systems, including solution boxes, interfaces, and adding ions or molecules to existing systems.
ElectrolyteBox
¶
Bases: WaterBox
Class for electrolyte solution box configuration.
This class extends WaterBox to handle uniform electrolyte solutions with specified solutes and concentrations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
Union[List, ndarray]
|
Box dimensions as [a, b, c] or [[a1, a2], [b1, b2], [c1, c2]] |
required |
solutes
|
Dict[str, float]
|
Dictionary mapping solute names to concentrations in mol/L |
required |
Source code in toolbox/io/build.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
__init__(boundary, solutes, **kwargs)
¶
Initialize ElectrolyteBox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
Union[List, ndarray]
|
Box dimensions |
required |
solutes
|
Dict[str, float]
|
Dictionary mapping solute names to concentrations in mol/L |
required |
**kwargs
|
Additional keyword arguments passed to parent class |
{}
|
Source code in toolbox/io/build.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
write(fname, n_wat=None, seed=-1, verbose=False, **kwargs)
¶
Write electrolyte box configuration to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Output filename |
required |
n_wat
|
Optional[int]
|
Number of water molecules. If None, uses calculated value from density |
None
|
seed
|
int
|
Random seed for reproducible molecule placement. Use -1 for random behavior |
-1
|
verbose
|
bool
|
If True, keeps temporary files, by default False |
False
|
**kwargs
|
Additional keyword arguments passed to ase.io.write |
{}
|
Source code in toolbox/io/build.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
Interface
¶
Class for creating interface systems.
This class creates interface systems between a slab and water box for electrochemical simulations.
Source code in toolbox/io/build.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
__init__(slab, l_water=30)
¶
Initialize Interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slab
|
Atoms
|
Slab atoms object |
required |
l_water
|
float
|
Length of water box in Ã…, by default 30 |
30
|
Source code in toolbox/io/build.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
run(rho=1.0, n_wat=None, seed=-1, sol=None, verbose=False)
¶
Create interface system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
float
|
Water density in g/cm³, by default 1.0 |
1.0
|
n_wat
|
Optional[int]
|
Number of water molecules, by default None |
None
|
seed
|
int
|
Random seed, by default -1 |
-1
|
sol
|
Optional[SolutionBox]
|
Solution box object, by default None |
None
|
verbose
|
bool
|
If True, keeps temporary files, by default False |
False
|
Returns:
| Type | Description |
|---|---|
Atoms
|
Combined interface system |
Source code in toolbox/io/build.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
SolutionBox
¶
Base class for solution box configuration.
This class defines the boundary conditions for solution systems with optional slit geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
Union[List, ndarray]
|
Box dimensions as [a, b, c] or [[a1, a2], [b1, b2], [c1, c2]] |
required |
slit
|
Union[float, List, ndarray]
|
Slit distance or dimensions, by default 1.0 |
1.0
|
Source code in toolbox/io/build.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
__init__(boundary, slit=1.0)
¶
Initialize SolutionBox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
Union[List, ndarray]
|
Box dimensions |
required |
slit
|
Union[float, List, ndarray]
|
Slit distance or dimensions, by default 1.0 |
1.0
|
Source code in toolbox/io/build.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
WaterBox
¶
Bases: SolutionBox
Class for water box configuration.
This class extends SolutionBox to specifically handle water molecules with density calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
Union[List, ndarray]
|
Box dimensions as [a, b, c] or [[a1, a2], [b1, b2], [c1, c2]] |
required |
slit
|
Union[float, List, ndarray]
|
Slit distance or dimensions, by default 1.0 |
1.0
|
rho
|
float
|
Water density in g/cm³ |
1.0
|
Source code in toolbox/io/build.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
__init__(boundary, slit=1.0, rho=1.0)
¶
Initialize WaterBox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
Union[List, ndarray]
|
Box dimensions |
required |
slit
|
Union[float, List, ndarray]
|
Slit distance or dimensions, by default 1.0 |
1.0
|
rho
|
float
|
Water density in g/cm³, by default 1.0 |
1.0
|
Source code in toolbox/io/build.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
write(fname, n_wat=None, seed=-1, verbose=False, **kwargs)
¶
Write water box configuration to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Output filename |
required |
n_wat
|
Optional[int]
|
Number of water molecules. If None, uses calculated value from density |
None
|
seed
|
int
|
Random seed for reproducible molecule placement. Use -1 for random behavior |
-1
|
verbose
|
bool
|
If True, keeps temporary files, by default False |
False
|
**kwargs
|
Additional keyword arguments passed to ase.io.write |
{}
|
Source code in toolbox/io/build.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
add_ion(atoms, ion, region, cutoff=2.0, max_trial=500)
¶
Add an ion to atoms system in specified region.
This function attempts to place an ion in the specified region without overlapping with existing atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Existing atoms system |
required |
ion
|
Atoms
|
Ion to add (single atom) |
required |
region
|
list
|
Region boundaries as [x_min, x_max, y_min, y_max, z_min, z_max] |
required |
cutoff
|
float
|
Minimum distance from existing atoms, by default 2.0 |
2.0
|
max_trial
|
int
|
Maximum number of placement attempts, by default 500 |
500
|
Returns:
| Type | Description |
|---|---|
Atoms or None
|
New atoms system with ion added, or None if placement failed |
Examples:
>>> from ase import io
>>> atoms = io.read("coord.xyz")
>>> ion = Atoms("K")
>>> atoms = add_ion(atoms, ion, [8.0, 13.0])
>>> ion = io.read("ClO4.pdb")
>>> atoms = add_ion(atoms, ion, [8.0, 13.0])
>>> print(atoms)
Source code in toolbox/io/build.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
add_water(atoms, region, cutoff=2.0, max_trial=500)
¶
Add a water molecule to atoms system in specified region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Existing atoms system |
required |
region
|
list
|
Region boundaries as [x_min, x_max, y_min, y_max, z_min, z_max] |
required |
cutoff
|
float
|
Minimum distance from existing atoms, by default 2.0 |
2.0
|
max_trial
|
int
|
Maximum number of placement attempts, by default 500 |
500
|
Returns:
| Type | Description |
|---|---|
Atoms or None
|
New atoms system with water added, or None if placement failed |
Source code in toolbox/io/build.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
get_region_random_location(atoms, region, extent=0.9)
¶
Generate random location within specified region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Atoms system for box dimensions |
required |
region
|
list
|
Region boundaries as [x_min, x_max, y_min, y_max, z_min, z_max] |
required |
extent
|
float
|
Fraction of box extent to use, by default 0.9 |
0.9
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Random position [x, y, z] within region |
Source code in toolbox/io/build.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
is_atom_overlap(atoms, index, atom_num=1, r=1.5)
¶
Check if atoms overlap with existing atoms.
This function checks if specified atoms in a molecule or ion overlap with existing atoms in the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Existing atoms system |
required |
index
|
int
|
Index of first atom in the added molecule/ion |
required |
atom_num
|
int
|
Number of atoms in the added molecule/ion, by default 1 |
1
|
r
|
float
|
Minimum distance between atoms, recommended 1.0-1.8, by default 1.5 |
1.5
|
Returns:
| Type | Description |
|---|---|
bool
|
True if atoms overlap, False otherwise |
Source code in toolbox/io/build.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
random_rotation_matrix()
¶
Generate a random 3D rotation matrix.
Returns:
| Type | Description |
|---|---|
ndarray
|
3x3 rotation matrix |
Source code in toolbox/io/build.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
CP2K I/O¶
toolbox.io.cp2k
¶
CP2K input/output module.
This module provides classes for generating CP2K input files and parsing CP2K output files, including energies, forces, and various properties.
Cp2kCube
¶
Class for handling CP2K cube files.
This class provides methods to read and analyze cube files generated by CP2K, including electron density, potential, and other volumetric data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to cube file |
required |
Source code in toolbox/io/cp2k.py
1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 | |
dipole
property
¶
Dipole moment [e A].
mesh
property
¶
Mesh for cube data.
get_ave_cube(axis=2, gaussian_sigma=0.0)
¶
Get averaged cube data along specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
int
|
Axis along which to average (0=x, 1=y, 2=z), by default 2 |
2
|
gaussian_sigma
|
float
|
Standard deviation for Gaussian smoothing, by default 0.0 |
0.0
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing (grid, averaged_data, smoothed_data) |
Source code in toolbox/io/cp2k.py
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 | |
Cp2kHartreeCube
¶
Bases: Cp2kCube
Class for handling CP2K Hartree potential cube files.
This class extends Cp2kCube to specifically handle Hartree potential data, including methods to calculate potential drops and related properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to Hartree potential cube file |
required |
vac_region
|
list
|
Vacuum region boundaries [start, end], by default None |
None
|
Source code in toolbox/io/cp2k.py
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 | |
dipole
property
¶
Calculate dipole moment from potential drop.
Returns:
| Type | Description |
|---|---|
float
|
Dipole moment in e·Å |
potdrop
property
¶
Calculate potential drop across the vacuum region.
Returns:
| Type | Description |
|---|---|
float
|
Potential drop in V |
get_ave_cube(axis=2, gaussian_sigma=0)
¶
Get averaged Hartree potential cube data along specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
int
|
Axis along which to average (0=x, 1=y, 2=z), by default 2 |
2
|
gaussian_sigma
|
float
|
Standard deviation for Gaussian smoothing, by default 0 |
0
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing (grid, averaged_data, smoothed_data) in eV |
Source code in toolbox/io/cp2k.py
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 | |
set_cross_area(cross_area)
¶
Set cross-sectional area for dipole calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cross_area
|
float
|
Cross-sectional area in Ų |
required |
Source code in toolbox/io/cp2k.py
1700 1701 1702 1703 1704 1705 1706 1707 1708 | |
set_vac_region(vac_region)
¶
Set vacuum region for potential drop calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vac_region
|
list
|
Vacuum region boundaries [start, end] |
required |
Source code in toolbox/io/cp2k.py
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 | |
Cp2kInput
¶
Class for CP2K input file generation (on the basis of templates).
Attributes:
| Name | Type | Description |
|---|---|---|
atoms |
ASE Atoms object
|
TBC |
input_type |
str
|
TBC |
pp_dir |
str
|
directory for basis set, peusudopotential, etc. |
wfn_restart |
str
|
wfn file for restart, see ref: |
qm_charge |
float
|
charge in QS |
multiplicity |
int
|
ref: |
uks |
boolen
|
ref: |
cutoff |
int
|
ref: |
rel_cutoff |
int
|
ref: |
Examples:
>>> from ase import io
>>> from toolbox.io.cp2k import Cp2kInput
>>> atoms = io.read("POSCAR")
>>> input = Cp2kInput(atoms,
>>> pp_dir="/data/basis",
>>> hartree=True,
>>> eden=True)
>>> input.write()
Source code in toolbox/io/cp2k.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
set_cutoff(cutoff)
¶
Set plane wave cutoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Plane wave cutoff in Ry |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for cutoff |
Source code in toolbox/io/cp2k.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
set_dip_cor(flag)
¶
Set surface dipole correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to apply surface dipole correction |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for dipole correction |
Source code in toolbox/io/cp2k.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
set_eden(flag)
¶
Set electron density cube output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to output electron density cube |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for electron density output |
Source code in toolbox/io/cp2k.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
set_efield(flag)
¶
Set electric field cube output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to output electric field cube |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for electric field output |
Source code in toolbox/io/cp2k.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
set_eps_scf(eps_scf)
¶
Set SCF convergence threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eps_scf
|
float
|
SCF convergence threshold |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for SCF convergence threshold |
Source code in toolbox/io/cp2k.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
set_extended_fft_lengths(flag)
¶
Set extended FFT lengths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to use extended FFT lengths |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for extended FFT lengths |
Source code in toolbox/io/cp2k.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
set_hartree(flag)
¶
Set Hartree potential cube output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to output Hartree potential cube |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for Hartree potential output |
Source code in toolbox/io/cp2k.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
set_kind(kind_dict)
¶
Set atom kind parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind_dict
|
dict
|
dict to update kind section, for example: { "S": { "ELEMENT": "O", "BASIS_SET": "DZVP-MOLOPT-SR-GTH", "POTENTIAL": "GTH-PBE-q6" }, "Li": { "ELEMENT": "H", "BASIS_SET": "DZVP-MOLOPT-SR-GTH", "POTENTIAL": "GTH-PBE-q1" } } |
required |
Source code in toolbox/io/cp2k.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
set_kp(kp_mp)
¶
Set k-points mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kp_mp
|
tuple
|
K-point mesh as (kx, ky, kz) |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for k-points |
Source code in toolbox/io/cp2k.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
set_max_scf(max_scf)
¶
Set maximum SCF iterations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_scf
|
int
|
Maximum number of SCF iterations |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for maximum SCF iterations |
Source code in toolbox/io/cp2k.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
set_md_step(md_step)
¶
Set number of MD steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md_step
|
int
|
Number of MD steps |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for MD steps |
Source code in toolbox/io/cp2k.py
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
set_md_temp(md_temp)
¶
Set MD temperature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md_temp
|
float
|
Temperature for MD simulation |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for MD temperature |
Source code in toolbox/io/cp2k.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
set_md_timestep(md_timestep)
¶
Set MD timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md_timestep
|
float
|
Timestep for MD simulation |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for MD timestep |
Source code in toolbox/io/cp2k.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
set_mlwf(flag)
¶
Set maximally localized Wannier functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to enable MLWF calculation |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for MLWF settings |
Source code in toolbox/io/cp2k.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
set_mo(flag)
¶
Set molecular orbital cube output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to output molecular orbital cubes |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for MO output |
Source code in toolbox/io/cp2k.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
set_multiplicity(multiplicity)
¶
Set spin multiplicity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
multiplicity
|
int
|
Spin multiplicity of the system |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for multiplicity |
Source code in toolbox/io/cp2k.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
set_params(kwargs)
¶
Set parameters for CP2K input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
dict
|
Dictionary of parameters to set |
required |
Source code in toolbox/io/cp2k.py
77 78 79 80 81 82 83 84 85 86 87 | |
set_pdos(flag)
¶
Set projected density of states output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to output PDOS |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for PDOS output |
Source code in toolbox/io/cp2k.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
set_pp_dir(pp_dir)
¶
Set pseudopotential directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pp_dir
|
str
|
Directory containing basis sets and pseudopotentials |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for pseudopotential directory |
Source code in toolbox/io/cp2k.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
set_project(project_name)
¶
Set project name for CP2K calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
str
|
Project name for CP2K calculation |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for project name |
Source code in toolbox/io/cp2k.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
set_qm_charge(charge)
¶
Set quantum mechanical charge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charge
|
float
|
Total charge of the system |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for charge |
Source code in toolbox/io/cp2k.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
set_rel_cutoff(rel_cutoff)
¶
Set relative cutoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rel_cutoff
|
float
|
Relative cutoff for multi-grid |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for relative cutoff |
Source code in toolbox/io/cp2k.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
set_restart(flag)
¶
Set restart file for CP2K calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to use restart file |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for restart settings |
Source code in toolbox/io/cp2k.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
set_smear(flag)
¶
Set smearing method for SCF calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to enable smearing |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for smearing settings |
Source code in toolbox/io/cp2k.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
set_totden(flag)
¶
Set total density cube output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to output total density cube |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for total density output |
Source code in toolbox/io/cp2k.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
set_uks(flag)
¶
Set unrestricted Kohn-Sham calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool
|
Whether to use UKS calculation |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for UKS |
Source code in toolbox/io/cp2k.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
set_wfn_restart(wfn_file)
¶
Set wavefunction restart file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wfn_file
|
str or None
|
Path to wavefunction restart file |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Update dictionary for wavefunction restart file |
Source code in toolbox/io/cp2k.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
update_dp(dp_model)
¶
Update CP2K input with Deep Potential model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dp_model
|
str
|
Path to Deep Potential model file |
required |
Source code in toolbox/io/cp2k.py
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
write(output_dir='.', fp_params=None, save_dict=False)
¶
Generate coord.xyz and input.inp for CP2K calculation at output_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
directory to store coord.xyz and input.inp |
'.'
|
fp_params
|
dict
|
dict for updated parameters |
None
|
Source code in toolbox/io/cp2k.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
Cp2kOutput
¶
Class for parsing CP2K output files.
This class provides methods to extract various properties from CP2K output files, including energies, forces, charges, and other calculation results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to CP2K output file, by default "output.out" |
'output.out'
|
ignore_warning
|
bool
|
Whether to ignore SCF convergence warnings, by default False |
False
|
Source code in toolbox/io/cp2k.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 | |
atoms
property
¶
Get ASE Atoms object from CP2K output.
Returns:
| Type | Description |
|---|---|
Atoms
|
ASE Atoms object with positions, cell, and periodic boundary conditions |
charge
property
¶
Get system charge from CP2K output.
Returns:
| Type | Description |
|---|---|
int
|
Total charge of the system |
coord
property
¶
Get atomic coordinate from cp2k output.
Return: coord numpy array (n_atom, 3)
dipole_moment
property
¶
Get dipole moment from CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Dipole moment vector [x, y, z] in Debye |
energy
property
¶
Get total energy from CP2K output.
Returns:
| Type | Description |
|---|---|
float
|
Total energy in eV |
energy_dict
property
¶
Get detailed energy breakdown from CP2K output.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing various energy components in eV |
fermi
property
¶
Get Fermi energy from CP2K output.
Returns:
| Type | Description |
|---|---|
float
|
Fermi energy in eV |
force
property
¶
Get atomic force from cp2k output.
Return: force numpy array (n_atom, 3)
h_charge
property
¶
Get Hirshfeld charges from CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of Hirshfeld charges for each atom |
m_charge
property
¶
Get Mulliken charges from CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of Mulliken charges for each atom |
multiplicity
property
¶
Get spin multiplicity from CP2K output.
Returns:
| Type | Description |
|---|---|
int
|
Spin multiplicity of the system |
potdrop
property
¶
Calculate potential drop across the surface.
Returns:
| Type | Description |
|---|---|
float
|
Potential drop in V |
scf_loop
property
¶
Get number of SCF iterations.
Returns:
| Type | Description |
|---|---|
int
|
Number of SCF iterations, or -1 if SCF did not converge |
surf_dipole_moment
property
¶
Grep surface dipole moment.
Total dipole moment perpendicular to the slab [electrons-Angstroem]: -1.5878220042.
timing_dict
property
¶
Get timing information from CP2K output.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing timing information for different CP2K modules |
uks
property
¶
Check if calculation is spin-unrestricted.
Returns:
| Type | Description |
|---|---|
bool
|
True if calculation is spin-unrestricted (UKS), False otherwise |
worktime
property
¶
Get CP2K calculation time.
Returns:
| Type | Description |
|---|---|
float
|
Total calculation time in seconds |
grep_text_search(pattern)
¶
Search for a pattern in CP2K output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Regular expression pattern to search for |
required |
Returns:
| Type | Description |
|---|---|
str
|
Line containing the pattern, or empty string if not found |
Source code in toolbox/io/cp2k.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
grep_texts(start_pattern, end_pattern)
¶
Extract text between start and end patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_pattern
|
str
|
Regular expression pattern for start of text block |
required |
end_pattern
|
str
|
Regular expression pattern for end of text block |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing (nframe, data_lines) where nframe is the number of matching blocks and data_lines is a 2D array of the extracted text |
Source code in toolbox/io/cp2k.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
grep_texts_by_nlines(start_pattern, nlines)
¶
Extract a fixed number of lines after a pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_pattern
|
str
|
Regular expression pattern to search for |
required |
nlines
|
int
|
Number of lines to extract after the pattern |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing (nframe, data_lines) where nframe is the number of matching blocks and data_lines is a 2D array of the extracted text |
Source code in toolbox/io/cp2k.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
Cp2kPDOS
¶
Class for handling CP2K projected density of states (PDOS) files.
This class provides methods to read and analyze PDOS data from CP2K, including calculation of various electronic properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Path to PDOS file |
required |
Source code in toolbox/io/cp2k.py
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 | |
cbm
property
¶
Get conduction band minimum (CBM) energy.
Returns:
| Type | Description |
|---|---|
float
|
CBM energy relative to Fermi level in eV |
homo
property
¶
Get highest occupied molecular orbital (HOMO) energy.
Returns:
| Type | Description |
|---|---|
float
|
HOMO energy relative to Fermi level in eV |
lumo
property
¶
Get lowest unoccupied molecular orbital (LUMO) energy.
Returns:
| Type | Description |
|---|---|
float
|
LUMO energy relative to Fermi level in eV |
vbm
property
¶
Get valence band maximum (VBM) energy.
Returns:
| Type | Description |
|---|---|
float
|
VBM energy relative to Fermi level in eV |
get_dos(broadening=0.01, energy_step=0.01)
¶
Ref: https://manual.cp2k.org/trunk/CP2K_INPUT/FORCE_EVAL/PROPERTIES/BANDSTRUCTURE/DOS.html.
Source code in toolbox/io/cp2k.py
1739 1740 1741 1742 1743 1744 1745 1746 | |
get_pdos(broadening=0.01, energy_step=0.01, dos_type='total')
¶
Ref: https://manual.cp2k.org/trunk/CP2K_INPUT/FORCE_EVAL/PROPERTIES/BANDSTRUCTURE/DOS.html.
Source code in toolbox/io/cp2k.py
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 | |
get_raw_pdos(dos_type)
¶
Get raw PDOS data of specified type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dos_type
|
str
|
Type of PDOS to retrieve (e.g., 'total', 's', 'p', 'd', 'f') |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Raw PDOS data |
Raises:
| Type | Description |
|---|---|
NameError
|
If the specified PDOS type does not exist |
Source code in toolbox/io/cp2k.py
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 | |
MultiFrameCp2kOutput
¶
Bases: Cp2kOutput
Class for parsing CP2K output files with multiple frames.
This class extends Cp2kOutput to handle multi-frame calculations such as molecular dynamics or geometry optimizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to CP2K output file, by default "output.out" |
'output.out'
|
ignore_warning
|
bool
|
Whether to ignore SCF convergence warnings, by default False |
False
|
Source code in toolbox/io/cp2k.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 | |
atoms
property
¶
Get ASE Atoms object from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
Atoms
|
ASE Atoms object with positions, cell, and periodic boundary conditions |
dipole_moment
property
¶
Get dipole moment from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of dipole moment vectors [x, y, z] in Debye for each frame |
energy
property
¶
Get total energy from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
float
|
Total energy in eV |
energy_dict
property
¶
Get detailed energy breakdown from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing various energy components in eV for each frame |
fermi
property
¶
Get Fermi energy from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
float
|
Fermi energy in eV |
force
property
¶
Get atomic force from cp2k output.
Return: force numpy array (n_atom, 3)
h_charge
property
¶
Get Hirshfeld charges from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of Hirshfeld charges for each atom for each frame |
m_charge
property
¶
Get Mulliken charges from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of Mulliken charges for each atom for each frame |
potdrop
property
¶
Calculate potential drop across the surface from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of potential drops in V for each frame |
scf_loop
property
¶
Get number of SCF iterations from multi-frame CP2K output.
Returns:
| Type | Description |
|---|---|
int
|
Number of SCF iterations, or -1 if SCF did not converge |
surf_dipole_moment
property
¶
Grep surface dipole moment.
Total dipole moment perpendicular to the slab [electrons-Angstroem]: -1.5878220042.
gaussian_convolve(xs, ys, sigma)
¶
Convolve data with Gaussian kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
array_like
|
X values |
required |
ys
|
array_like
|
Y values to convolve |
required |
sigma
|
float
|
Standard deviation of Gaussian |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Convolved values |
Source code in toolbox/io/cp2k.py
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 | |
gaussian_kernel(bins, sigma)
¶
Generate Gaussian kernel for convolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
array_like
|
Array of bin centers |
required |
sigma
|
float
|
Standard deviation of Gaussian |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Gaussian kernel values |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If sigma is negative |
Source code in toolbox/io/cp2k.py
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 | |
generate_ids_list(ids)
¶
Generate compact list representation of IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
array_like
|
Array of integer IDs |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of IDs with ranges compressed (e.g., [1, 2..5, 7]) |
Source code in toolbox/io/cp2k.py
1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 | |
read_wannier_spread(fname='wannier_spread.out')
¶
Read wannier spread file generated by cp2k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
wannier_spread.out file name |
'wannier_spread.out'
|
Returns:
| Name | Type | Description |
|---|---|---|
wannier_spread |
numpy array
|
wannier spread data |
Source code in toolbox/io/cp2k.py
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
Deep Potential JAX¶
toolbox.io.dp_jax
¶
DeepMD JAX molecular dynamics module.
This module provides classes for running molecular dynamics simulations using DeepMD JAX implementation with trajectory dumping functionality.
Simulation
¶
Bases: Simulation
DeepMD JAX molecular dynamics simulation class.
This class extends the base DeepMD JAX Simulation class to provide trajectory dumping and logging functionality.
Example
setup simulation¶
sim = Simulation( model_path="model.pkl", # Has to be an 'energy' or 'dplr' model box=box, # Angstroms type_idx=type_idx, # here the index-element map (e.g. 0-Oxygen, 1-Hydrogen) must match the dataset used to train the model mass=[15.9994, 1.0078, 195.08], # Oxygen, Hydrogen routine="NVT", # 'NVE', 'NVT', 'NPT' (Nosé-Hoover) dt=0.5, # femtoseconds initial_position=initial_position, # Angstroms temperature=330, # Kelvin report_interval=1, # Report every 100 steps seed=np.random.randint(1, 1e5), # Random seed )
sim.run( n_steps, [ TrajDump(atoms, "pos_traj.xyz", 10, append=True), TrajDump(atoms, "vel_traj.xyz", 10, vel=True, append=True), ], )
Source code in toolbox/io/dp_jax.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
__del__()
¶
Restore stdout when object is deleted.
Source code in toolbox/io/dp_jax.py
157 158 159 160 161 | |
__init__(model_path, box, type_idx, mass, routine, dt, initial_position, log_file='deepmd_jax.stdout', **kwargs)
¶
Initialize Simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
Path to trained model file |
required |
box
|
array_like
|
Simulation box dimensions in Angstroms |
required |
type_idx
|
array_like
|
Index-element mapping for atom types |
required |
mass
|
array_like
|
Atomic masses |
required |
routine
|
str
|
Ensemble type ('NVE', 'NVT', 'NPT') |
required |
dt
|
float
|
Timestep in femtoseconds |
required |
initial_position
|
array_like
|
Initial atomic positions in Angstroms |
required |
log_file
|
Optional[str]
|
Log file path, by default "deepmd_jax.stdout" |
'deepmd_jax.stdout'
|
**kwargs
|
Additional keyword arguments |
{}
|
Source code in toolbox/io/dp_jax.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
run(steps, dump_list)
¶
Run the simulation for a number of steps.
Source code in toolbox/io/dp_jax.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
TrajDump
¶
Class for dumping trajectory data during simulation.
This class handles writing trajectory data at specified intervals during molecular dynamics simulations.
Source code in toolbox/io/dp_jax.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
__init__(atoms, fname, interval, vel=False, **kwargs)
¶
Initialize TrajDump.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Atoms object for the system |
required |
fname
|
str
|
Output filename |
required |
interval
|
int
|
Dump interval in timesteps |
required |
vel
|
bool
|
Whether to dump velocities, by default False |
False
|
**kwargs
|
Additional keyword arguments for writing |
{}
|
Source code in toolbox/io/dp_jax.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
write(positions, cell)
¶
Write current frame to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
array_like
|
Atomic positions |
required |
cell
|
array_like
|
Unit cell vectors |
required |
Source code in toolbox/io/dp_jax.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
DPData I/O¶
toolbox.io.dpdata
¶
DPData utility module.
This module provides utility functions for working with DPData format, including setting energies, forces, and updating atom types.
set_energy_and_forces(atoms, energy, forces)
¶
Set energy and forces to atoms object.
This function sets the energy and forces on an ASE Atoms object to make atoms.get_potential_energy() and atoms.get_forces() return the given energy and forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
The atoms object to modify |
required |
energy
|
float
|
The energy value to set |
required |
forces
|
ndarray
|
The forces array to set |
required |
Source code in toolbox/io/dpdata.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
update_atype(dname, type_map)
¶
Update atom types in multiple directories.
This function updates atom type files in all subdirectories to match a specified type mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dname
|
str
|
Directory name to search for type files |
required |
type_map
|
List[str]
|
List of element symbols in desired order |
required |
Source code in toolbox/io/dpdata.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
LAMMPS I/O¶
toolbox.io.lammps
¶
LAMMPS I/O module.
This module provides classes and functions for reading and writing LAMMPS data files, dump files, and log files.
DPLRLammpsData
¶
Bases: LammpsData
Class for DPLR LAMMPS data files.
This class extends LammpsData to handle DPLR (Deep Potential Learning and Reproducing) specific data format.
Example
atoms = io.read("coord.xyz") sel_type = ["O"] sys_charge_dict = { "O": 6.0, "H": 1.0, } lmp_data = DPLRLammpsData(atoms, sel_type=sel_type, sys_charge_dict=sys_charge_dict) lmp_data.write("system.data", format="lammps-data", specorder=["O", "H"], atom_style="full")
Source code in toolbox/io/lammps.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
write(out_file='system.data', specorder=None, **kwargs)
¶
Write DPLR LAMMPS data file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_file
|
str
|
Output filename, by default "system.data" |
'system.data'
|
specorder
|
list
|
Specification order for atom types |
None
|
**kwargs
|
Additional keyword arguments for writing |
{}
|
Source code in toolbox/io/lammps.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
DPLRRestartLammpsData
¶
Bases: LammpsData
Class for DPLR restart LAMMPS data files.
This class extends LammpsData to handle DPLR restart files with specific velocity and topology information.
Example
atoms = io.read("after_system.data", format="lammps-data", sort_by_id=True, Z_of_type={1: 8, 2: 1, 3: 2} ) sel_type = ["O"] lmp_data = DPLRRestartLammpsData(atoms, sel_type=sel_type) lmp_data.write("restart_system.data", format="lammps-data", specorder=["O", "H", "He"], atom_style="full")
Source code in toolbox/io/lammps.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
LammpsData
¶
Class for writing LAMMPS data files from ASE Atoms objects.
This class provides functionality to convert ASE Atoms objects to LAMMPS data format with various atom styles.
Source code in toolbox/io/lammps.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
__init__(atoms)
¶
Initialize LammpsData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object to convert to LAMMPS data format |
required |
Source code in toolbox/io/lammps.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
set_angles(angles)
¶
Set angles between atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angles
|
array_like
|
Array of angles with shape (n_angles, 5) |
required |
Source code in toolbox/io/lammps.py
242 243 244 245 246 247 248 249 250 | |
set_atype(atype)
¶
Set atom types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atype
|
array_like
|
Array of atom types |
required |
Source code in toolbox/io/lammps.py
209 210 211 212 213 214 215 216 217 | |
set_atype_from_specorder(specorder)
¶
Set atom types from specification order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specorder
|
list
|
List of element symbols in desired order |
required |
Source code in toolbox/io/lammps.py
219 220 221 222 223 224 225 226 227 228 229 230 | |
set_bonds(bonds)
¶
Set bonds between atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bonds
|
array_like
|
Array of bonds with shape (n_bonds, 4) |
required |
Source code in toolbox/io/lammps.py
232 233 234 235 236 237 238 239 240 | |
set_charges(charges)
¶
Set atomic charges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charges
|
array_like
|
Array of atomic charges |
required |
Source code in toolbox/io/lammps.py
262 263 264 265 266 267 268 269 270 | |
set_dihedrals(dihedrals)
¶
Set dihedrals between atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dihedrals
|
array_like
|
Array of dihedrals with shape (n_dihedrals, 6) |
required |
Source code in toolbox/io/lammps.py
252 253 254 255 256 257 258 259 260 | |
set_res_id(res_id)
¶
Set residue IDs for atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_id
|
array_like
|
Array of residue IDs |
required |
Source code in toolbox/io/lammps.py
199 200 201 202 203 204 205 206 207 | |
set_velocities(velocities)
¶
Set atomic velocities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocities
|
array_like
|
Array of velocities with shape (n_atoms, 4) |
required |
Source code in toolbox/io/lammps.py
272 273 274 275 276 277 278 279 280 | |
write(out_file='system.data', **kwargs)
¶
Write LAMMPS data file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_file
|
str
|
Output filename, by default "system.data" |
'system.data'
|
**kwargs
|
Additional keyword arguments for writing |
{}
|
Source code in toolbox/io/lammps.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
LammpsDump
¶
Class for writing LAMMPS dump files.
This class provides functionality to write LAMMPS dump files from ASE trajectory objects with proper formatting.
Source code in toolbox/io/lammps.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
__init__(traj, type_map)
¶
Initialize LammpsDump.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj
|
Atoms or list
|
Trajectory data as ASE Atoms object or list |
required |
type_map
|
list or dict
|
Type mapping for atoms |
required |
Source code in toolbox/io/lammps.py
460 461 462 463 464 465 466 467 468 469 470 471 | |
make_body(atoms, atype_dict)
staticmethod
¶
Generate LAMMPS dump file body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Atoms object containing atomic data |
required |
atype_dict
|
dict
|
Dictionary mapping atom types to type numbers and elements |
required |
Returns:
| Type | Description |
|---|---|
str
|
Body string for LAMMPS dump file |
Source code in toolbox/io/lammps.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
make_header(atoms, ts)
staticmethod
¶
Generate LAMMPS dump file header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Atoms object containing atomic data |
required |
ts
|
int
|
Current timestep |
required |
Returns:
| Type | Description |
|---|---|
str
|
Header string for LAMMPS dump file |
Source code in toolbox/io/lammps.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
write(start=0, step=1, out_file='out.lammpstrj', append=False)
¶
Write LAMMPS dump file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
Starting timestep, by default 0 |
0
|
step
|
int
|
Timestep interval, by default 1 |
1
|
out_file
|
str
|
Output filename, by default "out.lammpstrj" |
'out.lammpstrj'
|
append
|
bool
|
Whether to append to existing file, by default False |
False
|
Source code in toolbox/io/lammps.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
LammpsLog
¶
Class for parsing LAMMPS log files.
This class provides functionality to extract information from LAMMPS log files, including timing and performance data.
Source code in toolbox/io/lammps.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
timing_breakdown
property
¶
Get timing breakdown from LAMMPS log file.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing timing information for different LAMMPS operations with time spent and percentage of total time |
__init__(fname='log.lammps')
¶
Initialize LammpsLog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to LAMMPS log file, by default "log.lammps" |
'log.lammps'
|
Source code in toolbox/io/lammps.py
600 601 602 603 604 605 606 607 608 609 610 611 612 | |
setup()
¶
Parse log file to extract performance information.
Source code in toolbox/io/lammps.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
OHHWaterLammpsData
¶
Bases: LammpsData
Class for O-H-H water LAMMPS data files.
This class extends LammpsData to specifically handle water molecules with O-H-H topology, automatically generating bonds and angles.
Source code in toolbox/io/lammps.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
__init__(atoms)
¶
Initialize OHHWaterLammpsData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object containing water molecules |
required |
Source code in toolbox/io/lammps.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
generate_water_bonds_and_angles(oxygen_ids, hydrogen_ids)
¶
Generate bonds and angles for water molecules.
This function creates bonds and angles for water molecules based on O-H-H topology.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oxygen_ids
|
array_like
|
Array of oxygen atom indices (1-based) |
required |
hydrogen_ids
|
array_like
|
Array of hydrogen atom indices (1-based) |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (bonds, angles) where: - bonds: array with shape (n_water*2, 4) - angles: array with shape (n_water, 5) |
Source code in toolbox/io/lammps.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | |
make_dump_body(atoms, atype_dict)
¶
Generate LAMMPS dump file body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Atoms object |
required |
atype_dict
|
dict
|
Atom type dictionary |
required |
Returns:
| Type | Description |
|---|---|
str
|
Body string for LAMMPS dump file |
Source code in toolbox/io/lammps.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
make_dump_header(atoms, ts)
¶
Generate LAMMPS dump file header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Atoms object |
required |
ts
|
int
|
Current timestep |
required |
Returns:
| Type | Description |
|---|---|
str
|
Header string for LAMMPS dump file |
Source code in toolbox/io/lammps.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
read_dump(dump_file='dump.lammpstrj')
¶
Read LAMMPS dump file and extract trajectory data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dump_file
|
str
|
Path to LAMMPS dump file, by default "dump.lammpstrj" |
'dump.lammpstrj'
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (coords, forces, boxs, type_list) where: - coords: array of atomic positions with shape (n_frames, n_atoms*3) - forces: array of atomic forces with shape (n_frames, n_atoms*3) - boxs: array of box vectors with shape (n_frames, 9) - type_list: array of atom types with shape (n_atoms,) |
Source code in toolbox/io/lammps.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
write_dump(traj, type_map, start=0, step=1, out_file='out.lammpstrj', append=False)
¶
Write LAMMPS dump file from trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj
|
Atoms or list
|
Trajectory data |
required |
type_map
|
list or dict
|
Type mapping for atoms |
required |
start
|
int
|
Starting timestep, by default 0 |
0
|
step
|
int
|
Timestep interval, by default 1 |
1
|
out_file
|
str
|
Output filename, by default "out.lammpstrj" |
'out.lammpstrj'
|
append
|
bool
|
Whether to append to existing file, by default False |
False
|
Source code in toolbox/io/lammps.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
Plotting Module¶
Core Plotting Functions¶
toolbox.plot.core
¶
Core plotting utilities module.
This module provides core plotting functions and utilities for creating various types of plots including learning curves, RMSE plots, binned statistics, and colored line plots.
ax_bin_stats(ax, x, y, bins)
¶
Create binned statistics plot on given axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes object |
required |
x
|
array_like
|
X values |
required |
y
|
array_like
|
Y values |
required |
bins
|
int
|
Number of bins |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing binned statistics data |
Source code in toolbox/plot/core.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
ax_colormap_lines(ax, xs, ys, labels, scale=(0.0, 1.0), colormap='GnBu', fmt='%f', **kwargs)
¶
Plot multiple colored lines on axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes object |
required |
xs
|
list
|
List of x data arrays |
required |
ys
|
list
|
List of y data arrays |
required |
labels
|
list
|
List of legend labels |
required |
scale
|
tuple
|
Scale range for normalization, by default (0.0, 1.0) |
(0.0, 1.0)
|
colormap
|
str
|
Matplotlib colormap name, by default "GnBu" |
'GnBu'
|
fmt
|
str
|
Format string for legend labels, by default "%f" |
'%f'
|
**kwargs
|
Additional keyword arguments passed to ax.plot |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
Function modifies the axes object in place |
Source code in toolbox/plot/core.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
ax_rmse(ax, x, y)
¶
Create RMSE scatter plot with reference line.
This function creates a scatter plot of data points with a reference line (y=x) for visual comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes object |
required |
x
|
array_like
|
X values |
required |
y
|
array_like
|
Y values |
required |
Source code in toolbox/plot/core.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
ax_setlabel(ax, xlabel, ylabel, **kwargs)
¶
Set axis labels for matplotlib axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes object |
required |
xlabel
|
str
|
X-axis label |
required |
ylabel
|
str
|
Y-axis label |
required |
**kwargs
|
Additional keyword arguments passed to set_xlabel/set_ylabel |
{}
|
Source code in toolbox/plot/core.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
plot_bin_stats(x, y, xlabel, ylabel, bins=None)
¶
Plot binned statistics with confidence intervals.
This function creates a plot showing mean, standard deviation, and min/max ranges for binned data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X values |
required |
y
|
array_like
|
Y values |
required |
xlabel
|
str
|
X-axis label |
required |
ylabel
|
str
|
Y-axis label |
required |
bins
|
int
|
Number of bins, by default len(x)//10 |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (fig, ax) containing matplotlib figure and axes |
Source code in toolbox/plot/core.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
plot_colormap_lines(xs, ys, legends, xlabel, ylabel, colormap='GnBu')
¶
Plot multiple lines with colormap.
This function creates a plot with multiple lines colored according to a colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
list
|
List of x data arrays |
required |
ys
|
list
|
List of y data arrays |
required |
legends
|
list
|
List of legend labels |
required |
xlabel
|
str
|
X-axis label |
required |
ylabel
|
str
|
Y-axis label |
required |
colormap
|
str
|
Matplotlib colormap name, by default "GnBu" |
'GnBu'
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (fig, ax) containing matplotlib figure and axes |
Source code in toolbox/plot/core.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
plot_lcurve(fname, col, xlabel=None, ylabel=None, **kwargs)
¶
Plot learning curve from data file.
This function reads a data file and plots a learning curve from the specified column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to data file |
required |
col
|
int
|
Column index to plot (0-based) |
required |
xlabel
|
str
|
X-axis label, by default None |
None
|
ylabel
|
str
|
Y-axis label, by default None |
None
|
**kwargs
|
Additional keyword arguments passed to ax.plot() |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (fig, ax, data) containing matplotlib figure, axes object, and loaded data |
Source code in toolbox/plot/core.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
plot_rmse(x, y, xlabel, ylabel, **kwargs)
¶
Plot RMSE scatter plot with reference line.
This function creates a scatter plot of data points with a reference line and calculates RMSE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X values |
required |
y
|
array_like
|
Y values |
required |
xlabel
|
str
|
X-axis label |
required |
ylabel
|
str
|
Y-axis label |
required |
**kwargs
|
Additional keyword arguments passed to plotting functions |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (fig, ax, rmse) containing matplotlib figure, axes object, and calculated RMSE |
Source code in toolbox/plot/core.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Deep Potential Plotting¶
toolbox.plot.dp
¶
Deep Potential plotting module.
This module provides specialized plotting classes for visualizing Deep Potential (DP) training data and results.
DPTrainFigure
¶
Bases: Figure
Figure class for DP training visualization.
This class extends Figure to provide specific functionality for visualizing Deep Potential training data.
Source code in toolbox/plot/dp.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
__init__(ax)
¶
Initialize DPTrainFigure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes object |
required |
Source code in toolbox/plot/dp.py
18 19 20 21 22 23 24 25 26 | |
setup(x, y, **kwargs)
¶
Set up DP training plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Training data features |
required |
y
|
array_like
|
Training data targets |
required |
**kwargs
|
Additional keyword arguments |
{}
|
Source code in toolbox/plot/dp.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
Figure Classes¶
toolbox.plot.figure
¶
Figure classes module.
This module provides base and specialized figure classes for creating matplotlib plots with consistent styling and layout.
Figure
¶
Base class for matplotlib figure creation.
This class provides a framework for creating matplotlib figures with consistent styling and layout.
Source code in toolbox/plot/figure.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__init__(**kwargs)
¶
Initialize Figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to plt.subplots |
{}
|
Source code in toolbox/plot/figure.py
21 22 23 24 25 26 27 28 29 | |
set_labels(kw, xlabel=None, ylabel=None, **kwargs)
¶
Set axis labels from keyword dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kw
|
str
|
Keyword to look up in label dictionary |
required |
xlabel
|
str
|
X-axis label, by default None |
None
|
ylabel
|
str
|
Y-axis label, by default None |
None
|
**kwargs
|
Additional keyword arguments passed to ax_setlabel |
{}
|
Source code in toolbox/plot/figure.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
setup(x, y, xlim=None, ylim=None, **kwargs)
¶
Set up basic plot with data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X data values |
required |
y
|
array_like
|
Y data values |
required |
xlim
|
tuple
|
X-axis limits as (min, max), by default None |
None
|
ylim
|
tuple
|
Y-axis limits as (min, max), by default None |
None
|
**kwargs
|
Additional keyword arguments passed to ax.plot |
{}
|
Source code in toolbox/plot/figure.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
FullCellFigure
¶
Bases: Figure
Figure class for full cell visualization.
This class extends Figure to provide specific functionality for visualizing systems with full periodic boundary conditions.
Source code in toolbox/plot/figure.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
__init__(**kwargs)
¶
Initialize FullCellFigure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to parent class |
{}
|
Source code in toolbox/plot/figure.py
91 92 93 94 95 96 97 98 99 | |
setup(x, y, xlim=None, ylim=None, z_surfs=None, **kwargs)
¶
Set up full cell visualization plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X data values |
required |
y
|
array_like
|
Y data values |
required |
xlim
|
tuple
|
X-axis limits as (min, max), by default None |
None
|
ylim
|
tuple
|
Y-axis limits as (min, max), by default None |
None
|
z_surfs
|
list
|
List of z-surface positions for visualization |
None
|
**kwargs
|
Additional keyword arguments passed to parent setup method |
{}
|
Source code in toolbox/plot/figure.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
HalfCellFigure
¶
Bases: Figure
Figure class for half cell visualization.
This class extends Figure to provide specific functionality for visualizing systems with half periodic boundary conditions (slab geometry).
Source code in toolbox/plot/figure.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
__init__(**kwargs)
¶
Initialize HalfCellFigure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to parent class |
{}
|
Source code in toolbox/plot/figure.py
151 152 153 154 155 156 157 158 159 | |
setup(x, y, xlim=None, ylim=None, z_surf=None, **kwargs)
¶
Set up half cell visualization plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X data values |
required |
y
|
array_like
|
Y data values |
required |
xlim
|
tuple
|
X-axis limits as (min, max), by default None |
None
|
ylim
|
tuple
|
Y-axis limits as (min, max), by default None |
None
|
z_surf
|
float
|
Z-surface position for visualization |
None
|
**kwargs
|
Additional keyword arguments passed to parent setup method |
{}
|
Source code in toolbox/plot/figure.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
Statistical Plotting¶
toolbox.plot.stats
¶
Statistical plotting module.
This module provides classes for creating statistical plots and performing statistical tests, including finite difference method testing.
FDMTest
¶
Finite difference method test for derivative.
This class implements finite difference methods to test numerical derivatives against analytical solutions.
Source code in toolbox/plot/stats.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
__init__(**kwargs)
¶
Initialize FDMTest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to plt.subplots |
{}
|
Source code in toolbox/plot/stats.py
23 24 25 26 27 28 29 30 31 32 33 | |
setup(x, y, dydx)
¶
Set up finite difference test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X values |
required |
y
|
array_like
|
Y values |
required |
dydx
|
array_like
|
Analytical derivative values |
required |
Source code in toolbox/plot/stats.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Plot Styles¶
toolbox.plot.style
¶
Matplotlib style module.
This module provides functionality for using custom matplotlib styles and color maps for scientific plotting.
References
use_style(style_name)
¶
Use custom matplotlib style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style_name
|
str
|
Name of the style to use |
required |
Notes
If the specified style is not found, falls back to fivethirtyeight style and prints a warning.
Source code in toolbox/plot/style.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
Utils Module¶
Bibliography Tools¶
toolbox.utils.bibtool
¶
Bibliography tool module.
This module provides utilities for managing bibliography files, including extracting citations from LaTeX files and exporting selected bibliography entries.
export(bib_in_file, tex_files=None, bib_out_file='export-ref.bib', online=True)
¶
Export a subset of the bib file that is used in the tex file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bib_in_file
|
str
|
Path to the original bib file |
required |
tex_files
|
Union[List[str], str]
|
Path to the tex file or list of tex files |
None
|
bib_out_file
|
str
|
Path to the output bib file |
'export-ref.bib'
|
online
|
bool
|
If True, it will try to get the bib entry from the DOI |
True
|
Source code in toolbox/utils/bibtool.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
extract_citation_keys(fnames)
¶
Grep all citation keys used in the tex file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fnames
|
str
|
Path to the tex file |
required |
Source code in toolbox/utils/bibtool.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
Data Utilities¶
toolbox.utils.data
¶
Data system management module.
This module provides base classes for managing data system configurations with read and write functionality.
DataSystem
¶
Base class for data system management.
This class provides a framework for reading and writing data system configurations.
Source code in toolbox/utils/data.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
__init__()
¶
Initialize DataSystem.
Source code in toolbox/utils/data.py
15 16 17 | |
read()
¶
Read data system configuration.
Source code in toolbox/utils/data.py
19 20 21 | |
write()
¶
Write data system configuration.
Source code in toolbox/utils/data.py
23 24 25 | |
Mathematical Functions¶
toolbox.utils.math
¶
Mathematical utilities module.
This module provides various mathematical functions for data analysis, including statistical functions, interpolation, integration, filtering, and error metrics.
block_ave(_x, _y, l_block)
¶
Calculate block averages of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_x
|
array_like
|
Input x values |
required |
_y
|
array_like
|
Input y values |
required |
l_block
|
int
|
Block size for averaging |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (x_ave, y_ave) containing block-averaged values |
Source code in toolbox/utils/math.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
cumave(data)
¶
Calculate cumulative average of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array_like
|
Input data |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
Cumulative average values |
Source code in toolbox/utils/math.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
error_test(y_true, y_pred)
¶
Calculate regression error metrics.
This function calculates various regression error metrics between true and predicted values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
array_like
|
True values |
required |
y_pred
|
array_like
|
Predicted values |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing error metrics: - max_err: Maximum error - mae: Mean absolute error - rmse: Root mean squared error - r2: R-squared score - mape: Mean absolute percentage error |
Source code in toolbox/utils/math.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
gaussian_filter(data, bin_edge, sigma, weight=None)
¶
Apply Gaussian filter to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array_like
|
Input data to filter |
required |
bin_edge
|
array_like
|
Bin edges for filtering |
required |
sigma
|
float
|
Gaussian standard deviation |
required |
weight
|
array_like
|
Weights for each data point |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (bins, filtered_data) |
Source code in toolbox/utils/math.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
gaussian_func(x, mu=0, sigma=1)
¶
Gaussian probability density function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input values |
required |
mu
|
float
|
Mean of the distribution, by default 0 |
0
|
sigma
|
float
|
Standard deviation, by default 1 |
1
|
Returns:
| Type | Description |
|---|---|
array_like
|
Gaussian probability density values |
Source code in toolbox/utils/math.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
gaussian_int(x, mu, sigma)
¶
Gaussian cumulative distribution function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input values |
required |
mu
|
float
|
Mean of the distribution |
required |
sigma
|
float
|
Standard deviation |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
Gaussian cumulative distribution values |
Source code in toolbox/utils/math.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
get_bin_ave(data, bin_size=10)
¶
Calculate binned averages of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array_like
|
Input data to bin |
required |
bin_size
|
int
|
Size of each bin, by default 10 |
10
|
Returns:
| Type | Description |
|---|---|
array_like
|
Binned averages |
Source code in toolbox/utils/math.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
get_dev(x, y)
¶
Calculate derivative dy/dx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input x values |
required |
y
|
array_like
|
Input y values |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (x_mid, dy/dx) where x_mid are midpoints |
Source code in toolbox/utils/math.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
get_int(x, y)
¶
Calculate numerical integral using trapezoidal rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input x values |
required |
y
|
array_like
|
Input y values |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (x_mid, integral) where x_mid are midpoints |
Source code in toolbox/utils/math.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
get_int_array(x, ys)
¶
Calculate numerical integrals for multiple y arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input x values |
required |
ys
|
array_like
|
Multiple y arrays with shape (n_arrays, n_points) |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (x_mid, integrals) where x_mid are midpoints |
Source code in toolbox/utils/math.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
handle_zero_division(x, y, threshold=None)
¶
Handle division by zero with optional threshold.
This function safely divides x by y, handling zero division with optional threshold masking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Numerator values |
required |
y
|
array_like
|
Denominator values |
required |
threshold
|
float
|
Threshold below which y values are set to zero |
None
|
Returns:
| Type | Description |
|---|---|
array_like
|
Result of x/y with safe division |
Source code in toolbox/utils/math.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
interp(x, dataset)
¶
Interpolate y values from dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
X values to interpolate at |
required |
dataset
|
array_like
|
Dataset with dataset[0] = x_values, dataset[1] = y_values |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
Interpolated y values |
Source code in toolbox/utils/math.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
vec_project(vec, unit_vec)
¶
Project vector onto unit vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
array_like
|
Vector to project |
required |
unit_vec
|
array_like
|
Unit vector to project onto |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
Projected vector |
Source code in toolbox/utils/math.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
Optimizer¶
toolbox.utils.optimizer
¶
Optimizer module.
This module provides classes and functions for optimization using various linear regression methods.
Optimizer
¶
Optimizer for linear regression models.
This class provides various optimization methods for fitting linear models to data.
Source code in toolbox/utils/optimizer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__init__(method='ols_cut')
¶
Initialize Optimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Optimization method to use, by default "ols_cut" |
'ols_cut'
|
Source code in toolbox/utils/optimizer.py
20 21 22 23 24 25 26 27 28 | |
run(x, y, **kwargs)
¶
Run optimization with specified method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input features |
required |
y
|
array_like
|
Target values |
required |
**kwargs
|
Additional keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
array_like
|
Optimization result |
Source code in toolbox/utils/optimizer.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
Toy Models¶
toolbox.utils.toy_model
¶
Toy model module.
This module provides simple physics models for educational purposes, including a parallel plate capacitor model.
ParallelPlateCapacitor
¶
Class for parallel plate capacitor calculations.
This class models a parallel plate capacitor system with configurable permittivity, plate distance, and capacitance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon_r
|
float
|
Relative permittivity |
None
|
d
|
float
|
Distance between plates in Angstroms |
None
|
capacitance
|
float
|
Capacitance in μF/cm² |
None
|
Examples:
>>> obj = ParallelPlateCapacitor(epsilon_r=10.0, d=4.0)
>>> print(obj)
>>> obj = ParallelPlateCapacitor(capacitance=20.0, d=4.0)
>>> print(obj)
Source code in toolbox/utils/toy_model.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
capacitance
property
¶
Get capacitance in μF/cm².
d_angstrom
property
¶
Get plate distance in Angstroms.
epsilon_r
property
¶
Get relative permittivity.
__init__(epsilon_r=None, d=None, capacitance=None)
¶
Initialize ParallelPlateCapacitor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon_r
|
Optional[float]
|
Relative permittivity, by default None |
None
|
d
|
Optional[float]
|
Distance between plates in Angstroms, by default None |
None
|
capacitance
|
Optional[float]
|
Capacitance in μF/cm², by default None |
None
|
Source code in toolbox/utils/toy_model.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
__repr__()
¶
Return string representation of the capacitor.
Returns:
| Type | Description |
|---|---|
str
|
String representation showing key parameters |
Source code in toolbox/utils/toy_model.py
87 88 89 90 91 92 93 94 95 | |
Unit Conversion¶
toolbox.utils.unit
¶
Physical constants and unit conversions.
General Utilities¶
toolbox.utils.utils
¶
Utility functions for computational chemistry and materials science.
This module provides a collection of utility functions for various tasks including: - Dictionary manipulation and file I/O operations - CP2K input file generation - Density and concentration calculations - Water molecule analysis and manipulation - Lennard-Jones parameter calculations - Coordinate number calculations
The functions are designed to work with common scientific computing libraries such as NumPy, ASE, and MDAnalysis.
calc_coord_number(atoms, c_ids, neigh_ids, cutoff=None, voronoi=False)
¶
Calculate coordination numbers for specified atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object |
required |
c_ids
|
ndarray
|
Indices of central atoms |
required |
neigh_ids
|
ndarray
|
Indices of neighbor atoms |
required |
cutoff
|
Optional[float]
|
Distance cutoff for coordination calculation |
None
|
voronoi
|
bool
|
If True, use Voronoi method instead of cutoff |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of coordination numbers |
Source code in toolbox/utils/utils.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
calc_density(n, v, mol_mass)
¶
Calculate density (g/cm³) from the number of particles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int or ndarray
|
Number of particles |
required |
v
|
float or ndarray
|
Volume in ų |
required |
mol_mass
|
float
|
Molar mass in g/mol |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Density in g/cm³ |
Source code in toolbox/utils/utils.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
calc_lj_params(ks)
¶
Calculate and print Lennard-Jones parameters for element pairs.
This function calculates mixed Lennard-Jones parameters using the Lorentz-Berthelot combining rules and prints them to stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
List[str]
|
List of element symbols |
required |
Source code in toolbox/utils/utils.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
calc_molar_concentration(number_density, grid_volume)
¶
Calculate molar concentration from number density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_density
|
int, float, or np.ndarray
|
Number of particles per grid |
required |
grid_volume
|
float or ndarray
|
Volume of each grid in ų (angstrom cubed) |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Molar concentration in mol/L (moles of ions per liter of solution) |
Source code in toolbox/utils/utils.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | |
calc_number(rho, v, mol_mass)
¶
Calculate number of particles from density and volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
float or ndarray
|
Density in g/cm³ |
required |
v
|
float or ndarray
|
Volume in ų |
required |
mol_mass
|
float
|
Molar mass in g/mol |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of particles (rounded to integer) |
Source code in toolbox/utils/utils.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
calc_water_coord_number(atoms)
¶
Calculate coordination numbers for water molecules (O-H coordination).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object containing water molecules |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of coordination numbers for oxygen atoms |
Source code in toolbox/utils/utils.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
calc_water_density(n, v)
¶
Calculate water density using water molar mass (18.015 g/mol).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int or ndarray
|
Number of water molecules |
required |
v
|
float or ndarray
|
Volume in ų |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Water density in g/cm³ |
Source code in toolbox/utils/utils.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
calc_water_number(rho, v)
¶
Calculate number of water molecules from density and volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
float or ndarray
|
Water density in g/cm³ |
required |
v
|
float or ndarray
|
Volume in ų |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of water molecules |
Source code in toolbox/utils/utils.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
check_water(atoms)
¶
Check if all water molecules have correct coordination (2 H per O).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object containing water molecules |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all water molecules are correct, False otherwise |
Source code in toolbox/utils/utils.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
dict_to_cp2k_input(input_dict)
¶
Convert a dictionary to CP2K input file format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
Dict[str, Any]
|
Dictionary containing CP2K input parameters |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted CP2K input string |
Source code in toolbox/utils/utils.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
get_bins_from_bin_edge(bin_edges)
¶
Get bin centers from bin edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
ndarray or List[float]
|
Array of bin edges |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of bin centers |
Source code in toolbox/utils/utils.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
get_efields(delta_v, layer_thicknesses, eps)
¶
Calculate electric fields from voltage differences and dielectric properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_v
|
float
|
Voltage difference |
required |
layer_thicknesses
|
List[float]
|
List of layer thicknesses |
required |
eps
|
List[float]
|
List of dielectric constants |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of electric field values |
Source code in toolbox/utils/utils.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
iterdict(input_dict, out_list, loop_idx)
¶
Recursively generate a list of strings for CP2K input file formatting.
This function processes a nested dictionary structure and converts it into a formatted list of strings suitable for generating CP2K input files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
Dict[str, Any]
|
Dictionary containing CP2K input parameters |
required |
out_list
|
List[str]
|
List of strings for printing (modified in-place) |
required |
loop_idx
|
int
|
Record of loop levels in recursion |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
Formatted list of strings for CP2K input file |
Source code in toolbox/utils/utils.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
load_dict(fname, fmt=None)
¶
Load a dictionary from a file in various formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Input filename |
required |
fmt
|
Optional[str]
|
File format (json, csv, pkl, hdf5, yaml). If None, inferred from extension. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Loaded dictionary |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the format is not supported |
NotImplementedError
|
If HDF5 format is requested (not implemented) |
Source code in toolbox/utils/utils.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
load_dict_csv(fname)
¶
Load dictionary from CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Input filename |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Loaded dictionary |
Source code in toolbox/utils/utils.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
load_dict_hdf5(fname)
¶
Load dictionary from HDF5 file (not implemented).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Input filename |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This function is not implemented |
Source code in toolbox/utils/utils.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
load_dict_json(fname)
¶
Load dictionary from JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Input filename |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Loaded dictionary |
Source code in toolbox/utils/utils.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
load_dict_pkl(fname)
¶
Load dictionary from pickle file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Input filename |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Loaded dictionary |
Source code in toolbox/utils/utils.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
load_dict_yaml(fname)
¶
Load dictionary from YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Input filename |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Loaded dictionary |
Source code in toolbox/utils/utils.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
safe_makedirs(dname)
¶
Create directory if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dname
|
str
|
Directory path to create |
required |
Source code in toolbox/utils/utils.py
402 403 404 405 406 407 408 409 410 411 412 | |
safe_symlink(src, dst, **kwargs)
¶
Create symbolic link if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source file path |
required |
dst
|
str
|
Destination path |
required |
**kwargs
|
Additional arguments for os.symlink |
{}
|
Source code in toolbox/utils/utils.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
save_dict(d, fname, fmt=None)
¶
Save a dictionary to a file in various formats.
Args: d: Dictionary to save fname: Output filename fmt: File format (json, csv, pkl, hdf5, yaml). If None, inferred from extension.
Raises:
| Type | Description |
|---|---|
KeyError: If the format is not supported
|
|
Source code in toolbox/utils/utils.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
save_dict_csv(d, fname)
¶
Save dictionary to CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dict[str, Any]
|
Dictionary to save |
required |
fname
|
str
|
Output filename |
required |
Source code in toolbox/utils/utils.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
save_dict_hdf5(d, fname)
¶
Save dictionary to HDF5 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dict[str, Any]
|
Dictionary to save |
required |
fname
|
str
|
Output filename |
required |
Source code in toolbox/utils/utils.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
save_dict_json(d, fname)
¶
Save dictionary to JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dict[str, Any]
|
Dictionary to save |
required |
fname
|
str
|
Output filename |
required |
Source code in toolbox/utils/utils.py
174 175 176 177 178 179 180 181 182 183 184 185 186 | |
save_dict_pkl(d, fname)
¶
Save dictionary to pickle file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dict[str, Any]
|
Dictionary to save |
required |
fname
|
str
|
Output filename |
required |
Source code in toolbox/utils/utils.py
206 207 208 209 210 211 212 213 214 215 216 217 218 | |
save_dict_yaml(d, fname)
¶
Save dictionary to YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dict[str, Any]
|
Dictionary to save |
required |
fname
|
str
|
Output filename |
required |
Source code in toolbox/utils/utils.py
239 240 241 242 243 244 245 246 247 248 249 250 251 | |
symlink(src, _dst)
¶
Create a symbolic link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source file path |
required |
_dst
|
str
|
Destination path |
required |
Source code in toolbox/utils/utils.py
138 139 140 141 142 143 144 145 146 147 148 149 150 | |
update_dict(old_d, update_d)
¶
Recursively update a dictionary with values from another dictionary.
Source: dpgen.generator.lib.cp2k
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_d
|
Dict[str, Any]
|
Original dictionary to be updated |
required |
update_d
|
Dict[str, Any]
|
Dictionary containing update values |
required |
Source code in toolbox/utils/utils.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
wrap_water(atoms)
¶
Make water molecules whole (keep O and H atoms together).
This function ensures that water molecules are not split across periodic boundaries. Works for pure water systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
ASE Atoms object containing water molecules |
required |
Returns:
| Type | Description |
|---|---|
Atoms
|
New Atoms object with wrapped water molecules |
Source code in toolbox/utils/utils.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
Machine Learning Module¶
TensorFlow Graph¶
toolbox.ml.tf_graph
¶
TensorFlow graph module.
This module provides functionality for loading and visualizing TensorFlow graphs from DeepMD models.
Graph
¶
from toolbox.ml import Graph.
Graph("graph.pb").run()
then you can access the graph with localhost:6006¶
Source code in toolbox/ml/tf_graph.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
__init__(dp_model='graph.pb')
¶
Initialize Graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dp_model
|
str
|
Path to Deep MD model file, by default "graph.pb" |
'graph.pb'
|
Source code in toolbox/ml/tf_graph.py
21 22 23 24 25 26 27 28 29 | |
run(port=6006)
¶
Run graph with TensorBoard visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
Port for TensorBoard server, by default 6006 |
6006
|
Source code in toolbox/ml/tf_graph.py
31 32 33 34 35 36 37 38 39 40 41 42 43 | |